[ 
https://issues.apache.org/jira/browse/LOG4J2-1255?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15102236#comment-15102236
 ] 

Gary Gregory edited comment on LOG4J2-1255 at 1/15/16 8:22 PM:
---------------------------------------------------------------

I had to roll an alternative flow logging API for a JDBC driver last year. 

Here is an example of implementing a JDBC API:

{code:java}
    @Override
    public ResultSet getAttributes(final String catalog, final String 
schemaPattern, final String typeNamePattern, final String attributeNamePattern)
            throws SQLException {
        final String method = traceEntry("getAttributes(catalog=%s, 
schemaPattern=%s, typeNamePattern=%s, attributeNamePattern=%s)", catalog, 
schemaPattern,
                typeNamePattern, attributeNamePattern);
        final ResultSet result = ...
        return traceExit(method, result);
    }
{code}

A common superclass we use for most JDBC API classes defines:

{code:java}
traceEntry(String)
traceEntry(String, Object)
traceEntry(String, Object, int[])
traceEntry(String, Object, Object)
traceEntry(String, Object, Object, Object)
traceEntry(String, Object, String[])
traceEntry(String, Object...)
traceExit(String)
traceExit(String, T)
{code}

The onus is on the developer to create a proper message template and pass 
objects appropriate for logging (not passwords for example).

The output looks like this:

{noformat}
2016-01-15 12:19:52,090 TRACE [main][com.rs.jdbc.dv.DvsDatabaseMetaData][ENTRY] 
Enter [email protected](catalog=null, 
schemaPattern=null, typeNamePattern=null, attributeNamePattern=null)
{noformat}

My pattern layout is 

{noformat}
%style{%d}{white} %highlight{%-5level}{TRACE=white} 
%style{[%t][%logger]%notEmpty{[%markerSimpleName]}}{white} 
%highlight{%msg%n%throwable}{TRACE=white}
{noformat}

My trace API adds a string version of the receiver, which looks like 
{{"DvsDatabaseMetaData@4cd8d871."}}


was (Author: garydgregory):
I had to roll an alternative flow logging API for a JDBC driver last year. 

Here is an example of implementing a JDBC API:

{code:java}
    @Override
    public ResultSet getAttributes(final String catalog, final String 
schemaPattern, final String typeNamePattern, final String attributeNamePattern)
            throws SQLException {
        final String method = traceEntry("getAttributes(catalog=%s, 
schemaPattern=%s, typeNamePattern=%s, attributeNamePattern=%s)", catalog, 
schemaPattern,
                typeNamePattern, attributeNamePattern);
        final ResultSet result = ...
        return traceExit(method, result);
    }
{code}

A common superclass we use for most JDBC API classes defines:

{code:java}
traceEntry(String)
traceEntry(String, Object)
traceEntry(String, Object, int[])
traceEntry(String, Object, Object)
traceEntry(String, Object, Object, Object)
traceEntry(String, Object, String[])
traceEntry(String, Object...)
traceExit(String)
traceExit(String, T)
{code}

The onus is on the developer to create a proper message template and pass 
objects appropriate for logging (not passwords for example).

> Logger.entry and Logger.exit should support Messages.
> -----------------------------------------------------
>
>                 Key: LOG4J2-1255
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1255
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: 2.5
>            Reporter: Ralph Goers
>            Assignee: Ralph Goers
>
> Logger.entry and Logger.exit currently do not support Message objects. This 
> reduces the flexibility of what can be logged on entry and exit to methods.



--
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