3 use base 'Log::Dispatch';
4 use FS::Record qw(qsearch qsearchs);
8 use vars qw(@STACK @LEVELS);
10 # override the stringification of @_ with something more sensible.
12 @LEVELS = qw(debug info notice warning error critical alert emergency);
14 foreach my $l (@LEVELS) {
17 $self->log( level => $l, message => @_ );
26 FS::Log - Freeside event log
33 my $log = FS::Log->new('do_something'); # set log context to 'do_something'
37 $log->error('something is wrong: '.$error);
40 # at this scope exit, do_something is removed from context
45 FS::Log provides an interface for logging errors and profiling information
46 to the database. FS::Log inherits from L<Log::Dispatch>.
54 Constructs and returns a log handle. CONTEXT must be a known context tag
55 indicating what activity is going on, such as the name of the function or
56 script that is executing.
58 Log context is a stack, and each element is removed from the stack when it
59 goes out of scope. So don't keep log handles in persistent places (i.e.
60 package variables or class-scoped lexicals).
68 my $min_level = FS::Conf->new->config('event_log_level') || 'info';
70 my $self = $class->SUPER::new(
71 outputs => [ [ '+FS::Log::Output', min_level => $min_level ] ],
73 $self->{'index'} = scalar(@STACK);
74 push @STACK, $context;
80 Returns the current context stack.
84 sub context { @STACK };
86 =item log LEVEL, MESSAGE[, OPTIONS ]
88 Like L<Log::Dispatch::log>, but OPTIONS may include:
91 - object (an <FS::Record> object to reference in this log message)
92 - tablename and tablenum (an alternate way of specifying 'object')
100 splice(@STACK, $self->{'index'}, 1); # delete the stack entry