mschilli / log4perl

Log4j Implementation For Perl
http://log4perl.com
Other
116 stars 67 forks source link

DBI appender max_col_size not applied to binds outside params #103

Open bnweiss opened 3 years ago

bnweiss commented 3 years ago

A configuration like so will not apply the max_col_size option and truncate the 7th bind field [message]:

log4perl.appender.DBI.sql = INSERT INTO log(logDate, filename, lineNum, logLevel, ip, userNum,message) VALUES (?,?,?,?,?,?,?)
log4perl.appender.DBI.params.1 = %d{yyyy-MM-dd HH:mm:ss}
log4perl.appender.DBI.params.2 = %F
log4perl.appender.DBI.params.3 = %L
log4perl.appender.DBI.params.4 = %p
log4perl.appender.DBI.params.5 = %X{ip}
log4perl.appender.DBI.params.6 = %X{user}
log4perl.appender.DBI.usePreparedStmt = 1
log4perl.appender.DBI.layout = Log::Log4perl::Layout::NoopLayout
log4perl.appender.DBI.warp_message = 0
log4perl.appender.DBI.max_col_size = 10

You can see in the code that the max_col_size is never applied to the "leftovers". https://github.com/mschilli/log4perl/blob/a361622da0a110d16a7efd61dab23c0d7a475eec/lib/Log/Log4perl/Appender/DBI.pm#L255

If I change the order of my binds however the max_col_size will be applied to the message field -

log4perl.appender.DBI.sql = INSERT INTO log(logDate, filename, lineNum, logLevel, ip, message, usernum) VALUES (?,?,?,?,?,?,?)
log4perl.appender.DBI.params.1 = %d{yyyy-MM-dd HH:mm:ss}
log4perl.appender.DBI.params.2 = %F
log4perl.appender.DBI.params.3 = %L
log4perl.appender.DBI.params.4 = %p
log4perl.appender.DBI.params.5 = %X{ip}
log4perl.appender.DBI.params.7 = %X{user}
log4perl.appender.DBI.usePreparedStmt = 1
log4perl.appender.DBI.layout = Log::Log4perl::Layout::NoopLayout
log4perl.appender.DBI.warp_message = 0
log4perl.appender.DBI.max_col_size = 10

Easy to fix and make a PR but I'm not sure if I am missing something else with how things are meant to work.

mohawk2 commented 2 years ago

If you make a PR, I believe that will make things be clearer :-)