1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
NAME
Log::Fast - Fast and flexible logger
VERSION
This document describes Log::Fast version v2.0.1
SYNOPSIS
use Log::Fast;
$LOG = Log::Fast->global();
$LOG = Log::Fast->new({
level => 'WARN',
prefix => '%D %T [%L] ',
type => 'fh',
fh => \*STDOUT,
});
use Sys::Syslog qw( LOG_DAEMON );
$LOG->config({
prefix => '',
type => 'unix',
path => '/dev/log',
facility => LOG_DAEMON,
add_timestamp => 1,
add_hostname => 1,
hostname => 'somehost',
ident => 'someapp',
add_pid => 1,
pid => $$,
});
$LOG->ident('anotherapp');
$LOG->level('INFO');
$LOG->ERR('Some error');
$LOG->WARN('Some warning');
$LOG->NOTICE('user %s logged in', $user);
$LOG->INFO('data loaded');
$LOG->DEBUG('user %s have %d things', $user, sub {
return SlowOperation_GetAmountOfThingsFor($user);
});
DESCRIPTION
This is very fast logger, designed for use in applications with
thousands high-level events/operations per second (like network servers
with thousands clients or web spiders which download hundreds url per
second).
For example, on Core2Duo sending about 5000 messages to log on enabled
log levels or 20000 messages on disabled log levels in one second will
slow down your application only by 2-3%.
Comparing to some other CPAN modules, this one (in average): faster
than Log::Dispatch in about 45 times, faster than Log::Handler in about
15 times, faster than Sys::Syslog in about 7 times, and slower than
Log::Syslog::Fast in about 2 times.
FEATURES
* Global and local logger objects
* Output to any open filehandle or local syslog
* 5 log levels: ERR, WARN, NOTICE, INFO, DEBUG
* Configurable prefix (log level, date/time, caller function name)
* sprintf() support
* Unicode support (UTF8)
* Can avoid calculating log message content on disabled log levels
INTERFACE
global
$LOG = Log::Fast->global();
When called first time will create global log object using default
options (you can reconfigure it using config() later).
Global log object is useful if your application consists of several
independent modules which should share same logging options configured
outside of these modules. In this case all these modules should use
same global() log object instead of creating new() independent log
objects in each module.
Return global log object.
new
$LOG = Log::Fast->new();
$LOG = Log::Fast->new( \%opt );
Create new log object, configured using defaults and user-provided
options, if any.
Return created log object.
config
$LOG->config( \%opt );
Reconfigure log object. Any options (see "OPTIONS") can be changed at
any time, including changing output {type} or setting options useless
with current output type (new values for these options will be used
later, if output type will be changed).
If you need to change only log {level} or syslog's {ident} you should
use level() or ident() methods because they are much faster than more
general config().
Return nothing. Throw exception if unable to connect to syslog.
level
$level = $LOG->level();
$level = $LOG->level( $new_level );
If $new_level given will change current log level. This is same as call
config({ level=>$new_level }) but much faster.
Return previous log level.
ident
$ident = $LOG->ident();
$ident = $LOG->ident( $new_ident );
If $new_ident given will change current syslog's ident. This is same as
call config({ ident=>$new_ident }) but much faster.
Return previous syslog's ident.
ERR
WARN
NOTICE
INFO
DEBUG
$LOG->ERR( $message )
$LOG->ERR( $format, @list )
$LOG->WARN( $message )
$LOG->WARN( $format, @list )
$LOG->NOTICE( $message )
$LOG->NOTICE( $format, @list )
$LOG->INFO( $message )
$LOG->INFO( $format, @list )
$LOG->DEBUG( $message )
$LOG->DEBUG( $format, @list )
Output $message to log using different log levels.
If $format, @list used instead of $message, then use sprintf($format,
@list) to calculate log message.
If @list will contain CODEREF, they will be called (in LIST context)
and returned values will be placed inside @list inplace of CODEREF.
This can be used to avoid calculating log message (or it part) on
disabled log levels - these CODEREF will be executed only on enabled
log levels. Example available in "SYNOPSIS".
If $message or items in @list will be Unicode strings, they will be
converted to UTF8 before sending to log.
Return nothing. Throw exception if fail to write message to log.
OPTIONS
Defaults for all options are:
level => 'DEBUG',
prefix => q{},
type => 'fh',
fh => \*STDERR,
# these will be used if you will call config({ type=>'unix' })
path => Sys::Syslog::_PATH_LOG() || '/dev/log',
facility => LOG_USER,
add_timestamp => 1,
add_hostname => 0,
hostname => Sys::Hostname::hostname(),
ident => ..., # calculated from $0
add_pid => 1,
pid => $$,
level
Current log level. Possible values are: 'ERR', 'WARN', 'NOTICE',
'INFO', 'DEBUG'.
Only messages on current or higher levels will be sent to log.
prefix
String, which will be output at beginning of each log message. May
contain these placeholders:
%L - log level of current message
%S - hi-resolution time (seconds.microseconds)
%D - current date in format YYYY-MM-DD
%T - current time in format HH:MM:SS
%P - caller's function package ('main' or 'My::Module')
%F - caller's function name
%_ - X spaces, where X is current stack depth
%% - % character
Example output with prefix '%D %T [%L]%_%P::%F() ':
2010-11-17 18:06:20 [INFO] main::() something from main script
2010-11-17 18:06:53 [INFO] main::a() something from a
2010-11-17 18:09:09 [INFO] main::b2() something from b1->b2
2010-11-17 18:06:56 [INFO] main::c() something from c
If it will be Unicode string, it will be converted to UTF8.
type
Output type. Possible values are: 'fh' (output to any already open
filehandle) and 'unix' (output to syslog using UNIX socket).
When {type} set to 'fh' you have to also set {fh} to any open
filehandle (like \*STDERR).
When {type} set to 'unix' you have to also set {path} to path to
existing UNIX socket (typically it's '/dev/log').
Luckily, default values for both {fh} and {path} are already
provided, so usually it's enough to just set {type}.
fh
File handle to write log messages if {type} set to 'fh'.
path
Syslog's UNIX socket path to write log messages if {type} set to
'unix'.
facility
Syslog's facility (see "Facilities" in Sys::Syslog for a list of
well-known facilities).
This module doesn't export any constants, so if you wanna change it
from default LOG_USER value, you should import facility constants
from Sys::Syslog module. Example available in "SYNOPSIS".
add_timestamp
If TRUE will include timestamp in syslog messages.
add_hostname
If TRUE will include hostname in syslog messages.
hostname
Host name which will be included in syslog messages if {add_hostname}
is TRUE.
ident
Syslog's ident (application name) field.
If it will be Unicode string, it will be converted to UTF8. Using
non-ASCII ALPHANUMERIC ident isn't allowed by RFC, but usually works.
add_pid
If TRUE will include PID in syslog messages.
pid
PID which will be included in syslog messages if {add_pid} is TRUE.
SPEED HINTS
Empty prefix is fastest. Prefixes %L, %P and %% are fast enough, %D and
%T has average speed, %S, %F and %_ are slowest.
Output to file is about 4 times faster than to syslog.
Calling log with single parameter is faster than with many parameters
(because in second case sprintf() have to be used).
SUPPORT
Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at
https://github.com/powerman/perl-Log-Fast/issues. You will be notified
automatically of any progress on your issue.
Source Code
This is open source software. The code repository is available for
public review and contribution under the terms of the license. Feel
free to fork the repository and submit pull requests.
https://github.com/powerman/perl-Log-Fast
git clone https://github.com/powerman/perl-Log-Fast.git
Resources
* MetaCPAN Search
https://metacpan.org/search?q=Log-Fast
* CPAN Ratings
http://cpanratings.perl.org/dist/Log-Fast
* AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Log-Fast
* CPAN Testers Matrix
http://matrix.cpantesters.org/?dist=Log-Fast
* CPANTS: A CPAN Testing Service (Kwalitee)
http://cpants.cpanauthors.org/dist/Log-Fast
AUTHOR
Alex Efros <powerman@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2010- by Alex Efros <powerman@cpan.org>.
This is free software, licensed under:
The MIT (X11) License
|