Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#61 Add a custom java.util.logging.level (AUDIT level)

1.1 release
open
nobody
audit (3)
7
2008-05-19
2008-05-02
André Pestana
No

It's important to separate business log from technical log. Creating a new level audit is a good way of separating jGuard audit data because using INFO level can bring more data from third part software that jGuard depends on. It's needed to change all log level from INFO to JG_AUDIT in jGuard filter and other internal business logs. An example of the custom level above:

package net.sf.jguard.audit;

import org.apache.log4j.Level;

/**
* @author <a href="mailto:andrepestana@yahoo.com">André Pestana</a>
*/
public class JGLevel extends Level
{

/**
*
*/
private static final long serialVersionUID = 1L;

/*
* Constructor
*/
public JGLevel(int level, String levelStr, int syslogEquivalent)
{
super(level, levelStr, syslogEquivalent);
}

public static JGLevel toLevel(int val, Level defaultLevel)
{
return JG_AUDIT;
}

public static JGLevel toLevel(String sArg, Level defaultLevel)
{

return JG_AUDIT;

}

public static final JGLevel JG_AUDIT = new JGLevel(60000, "JG_AUDIT", 0);

}

Discussion

  • André Pestana
    André Pestana
    2008-05-19

    Logged In: YES
    user_id=1699736
    Originator: YES

    I forgot that jGuard uses java.util.logging...

    So it can be done also in java.util.logging:

    import java.util.logging.Level;

    public class CustomLevel extends Level {

    /**
    * Log records whose level is <code>AUDIT</code> indicate business
    * message for audit.
    */
    public static final CustomLevel AUDIT = new CustomLevel ("AUDIT", 60000);
    protected CustomLevel(String name, int value)
    {
    super(name, value, null);
    }

    private static final long serialVersionUID = -2512532807894143749L;

    }

     
  • André Pestana
    André Pestana
    2008-05-19

    • summary: Add a new log4j level (JG_AUDIT level) --> Add a new java.util.level (AUDIT level)
     
  • André Pestana
    André Pestana
    2008-05-19

    • summary: Add a new java.util.level (AUDIT level) --> Add a custom java.util.logging.level (AUDIT level)