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 # subset of Log::Dispatch levels
21 foreach my $l (values %LEVELS) {
24 $self->log( level => $l, message => @_ );
33 FS::Log - Freeside event log
40 my $log = FS::Log->new('do_something'); # set log context to 'do_something'
44 $log->error('something is wrong: '.$error);
47 # at this scope exit, do_something is removed from context
52 FS::Log provides an interface for logging errors and profiling information
53 to the database. FS::Log inherits from L<Log::Dispatch>.
61 Constructs and returns a log handle. CONTEXT must be a known context tag
62 indicating what activity is going on, such as the name of the function or
63 script that is executing.
65 Log context is a stack, and each element is removed from the stack when it
66 goes out of scope. So don't keep log handles in persistent places (i.e.
67 package variables or class-scoped lexicals).
75 my $min_level = FS::Conf->new->config('event_log_level') || 'info';
77 my $self = $class->SUPER::new(
78 outputs => [ [ '+FS::Log::Output', min_level => $min_level ] ],
80 $self->{'index'} = scalar(@STACK);
81 push @STACK, $context;
87 Returns the current context stack.
91 sub context { @STACK };
93 =item log LEVEL, MESSAGE[, OPTIONS ]
95 Like L<Log::Dispatch::log>, but OPTIONS may include:
98 - object (an <FS::Record> object to reference in this log message)
99 - tablename and tablenum (an alternate way of specifying 'object')
107 splice(@STACK, $self->{'index'}, 1); # delete the stack entry
112 Subroutine. Returns ordered list of level nums.
122 Subroutine. Returns ordered map of level num => level name.
127 map { $_ => $LEVELS{$_} } levelnums;