From: Moritz Bunkus Date: Mon, 17 Jan 2011 16:25:50 +0000 (+0100) Subject: Logging von Datenbankzugriffen auch von Rose via Log::Log4perl und DBIx::Log4perl... X-Git-Tag: release-2.6.3~61^2~7^2~1^2~2^2~6 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=54d656bd6b68c1be6375080db05ac6f3d4a567ba;p=kivitendo-erp.git Logging von Datenbankzugriffen auch von Rose via Log::Log4perl und DBIx::Log4perl ermöglichen --- diff --git a/SL/DB.pm b/SL/DB.pm index b48a49e70..f90a9c637 100644 --- a/SL/DB.pm +++ b/SL/DB.pm @@ -13,6 +13,22 @@ __PACKAGE__->use_private_registry; my (%_db_registered, %_initial_sql_executed); +sub dbi_connect { + shift; + + return DBI->connect(@_) unless $::lx_office_conf{debug} && $::lx_office_conf{debug}->{dbix_log4perl}; + + require Log::Log4perl; + require DBIx::Log4perl; + + my $filename = $LXDebug::file_name; + my $config = $::lx_office_conf{debug}->{dbix_log4perl_config}; + $config =~ s/LXDEBUGFILE/${filename}/g; + + Log::Log4perl->init(\$config); + return DBIx::Log4perl->connect(@_); +} + sub create { my $domain = shift || SL::DB->default_domain; my $type = shift || SL::DB->default_type; diff --git a/config/lx_office.conf.default b/config/lx_office.conf.default index 10cf54c67..cd230d223 100644 --- a/config/lx_office.conf.default +++ b/config/lx_office.conf.default @@ -28,3 +28,21 @@ login = demo # location of history file for permanent history history_file = users/console_history + +[debug] +# Use DBIx::Log4perl for logging DBI calls. The string LXDEBUGFILE +# will be replaced by the file name configured for $::lxdebug. +dbix_log4perl = 0 +dbix_log4perl_config = log4perl.logger = FATAL, LOGFILE + = log4perl.appender.LOGFILE=Log::Log4perl::Appender::File + = log4perl.appender.LOGFILE.filename=LXDEBUGFILE + = log4perl.appender.LOGFILE.mode=append + = log4perl.appender.LOGFILE.Threshold = ERROR + = log4perl.appender.LOGFILE.layout=PatternLayout + = log4perl.appender.LOGFILE.layout.ConversionPattern=[%r] %F %L %c - %m%n + = log4perl.logger.DBIx.Log4perl=DEBUG, A1 + = log4perl.appender.A1=Log::Log4perl::Appender::File + = log4perl.appender.A1.filename=LXDEBUGFILE + = log4perl.appender.A1.mode=append + = log4perl.appender.A1.layout=Log::Log4perl::Layout::PatternLayout + = log4perl.appender.A1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n