Jeff Snow created LOG4J2-977:
--------------------------------

             Summary: Add maxLength parameter to Column element of JDBCAppender
                 Key: LOG4J2-977
                 URL: https://issues.apache.org/jira/browse/LOG4J2-977
             Project: Log4j 2
          Issue Type: Improvement
          Components: Appenders
    Affects Versions: 2.2, 2.1
            Reporter: Jeff Snow


For a Column element within the JDBCAppender, add a maxLength parameter to 
truncate the value to a maxLength.  This will help prevent exceptions when 
inserting rows into the database and the length of a string is greater than the 
size of a column.

For instance, the following would limit the value to 4000 characters by 
truncating message if the length is greater than 4000 characters.

<Column name="message" pattern="%message" isUnicode="false" maxLength="4000"/>

Note:  In log4j 1.x we solved this problem by coding a custom class that 
implemented the interface JDBCColumnHandler, but Log4j2 does not offer this 
interface:

public class MessageColumnHandler implements JDBCColumnHandler {
    @Override
    public Object getObject( final LoggingEvent pLoggingEvent, final String s, 
final String s2 ) throws Exception {
        return StringUtils.abbreviate( "intercepted: "
                    + pLoggingEvent.getRenderedMessage()
                     , 4000 );
    }
}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to