From: Kai P. <ka...@po...> - 2002-12-13 07:57:25
|
Hi, please do a commit after every execute. Otherwise, if the program crashes, the logs are rolled back and you cannot see whats happened. Some databases might be in an autocommit mode, where this is not a problem. I work with Oracle and the standard is to have no autocommit. Kai On Monday 09 December 2002 20:57, Kevin Goess wrote: > I needed to add logging to a database, here's a proposed solution. > > Log4j has a JDBCAppender with the warning: "This version of JDBCAppender > is very likely to be completely replaced in the future." The API is > kind of different, you call append() until the buffer is full, at which > point the an sth is created and executed on the buffer. So the API > isn't interchangeable with other appenders. > > So I've implemented a DBI appender that's completely controllable from > the config file, looking something like this: > > log4j.category = WARN, DBAppndr > log4j.appender.DBAppndr = Log::Log4perl::Appender::DBI > log4j.appender.DBAppndr.datasource = DBI:CSV:f_dir=t/tmp > log4j.appender.DBAppndr.username = bobjones > log4j.appender.DBAppndr.password = 12345 > log4j.appender.DBAppndr.sqlStatement = \ > insert into log4perltest \ > (level, message, shortmessage) \ > values (?,?,?) > log4j.appender.DBAppndr.params.1 = %p > log4j.appender.DBAppndr.params.2 = %m > log4j.appender.DBAppndr.params.3 = %5.5m > ... > > The code is based on Log::Dispatch::DBI by Tatsuhiko Miyagawa. His > module gets behavior changes via subclassing, but by the time I was done > I had overridden everything but DESTROY, so I just dropped the > dependency on his module. > > Below is the only change to existing code, the module and a unit test > are attached. Any comments or suggestions? > > > ============================================================ > --- lib/Log/Log4perl/Appender.pm 18 Nov 2002 20:03:39 -0000 > 1.17 +++ lib/Log/Log4perl/Appender.pm 9 Dec 2002 19:51:31 -0000 > @@ -120,7 +120,10 @@ > $level, > 3 + > $Log::Log4perl::caller_depth, > ); > - $self->{appender}->log(%$p); > + $self->{appender}->log(%$p, > + #these are used by our Appender::DBI > + log4p_category => $category, > + log4p_level => $level,); > > return 1; > } -- "I'd love to go out with you, but I'm taking punk totem pole carving." Unix, WinNT and MS-DOS. The Good, The Bad and The Ugly. Kai Poitschke MailTo:kai[_at_]poitschke[_dot_]de Date/Time: Fri Dec 13 08:52:55 MET 2002 |