enable CardFortress in test database, #71513
[freeside.git] / FS / FS / Log / Output.pm
1 package FS::Log::Output;
2 use base qw( Log::Dispatch::Output );
3
4 use FS::log;
5
6 sub new { # exactly by the book
7   my $proto = shift;
8   my $class = ref $proto || $proto;
9
10   my %p = @_;
11
12   my $self = bless {}, $class;
13
14   $self->_basic_init(%p);
15
16   return $self;
17 }
18
19 sub log_message {
20   my $self = shift;
21   my %m = @_;
22
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( $object->primary_key );
28
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.
33   }
34
35   my $entry = FS::log->new({
36       _date     => time,
37       agentnum  => $m{'agentnum'},
38       tablename => ($tablename || ''),
39       tablenum  => ($tablenum || ''),
40       level     => $self->_level_as_number($m{'level'}),
41       message   => $m{'message'},
42   });
43   my $error = $entry->insert( FS::Log->context );
44   if ( $error ) {
45     # guh?
46     warn "Error writing log entry: $error";
47   }
48 }
49
50 1;