From 54d656bd6b68c1be6375080db05ac6f3d4a567ba Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 17 Jan 2011 17:25:50 +0100 Subject: [PATCH] =?utf8?q?Logging=20von=20Datenbankzugriffen=20auch=20von?= =?utf8?q?=20Rose=20via=20Log::Log4perl=20und=20DBIx::Log4perl=20erm=C3=B6?= =?utf8?q?glichen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB.pm | 16 ++++++++++++++++ config/lx_office.conf.default | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) 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 -- 2.20.1