1 package FS::Log::Output;
3 use base Log::Dispatch::Output;
4 use FS::Record qw( dbdef );
6 sub new { # exactly by the book
8 my $class = ref $proto || $proto;
12 my $self = bless {}, $class;
14 $self->_basic_init(%p);
23 my $object = $m{'object'};
24 my ($tablename, $tablenum) = @m{'tablename', 'tablenum'};
25 if ( $object and $object->isa('FS::Record') ) {
26 $tablename = $object->table;
27 $tablenum = $object->get( dbdef->table($tablename)->primary_key );
29 # get the agentnum from the object if it has one
30 $m{'agentnum'} ||= $object->get('agentnum');
31 # maybe FS::cust_main_Mixin objects should use the customer's agentnum?
32 # I'm trying not to do database lookups in here, though.
35 my $entry = FS::log->new({
37 agentnum => $m{'agentnum'},
38 tablename => ($tablename || ''),
39 tablenum => ($tablenum || ''),
40 level => $self->_level_as_number($m{'level'}),
41 message => $m{'message'},
43 my $error = $entry->insert( FS::Log->context );
46 warn "Error writing log entry: $error";