com.stratelia.silverpeas.silvertrace
Class SilverLog

java.lang.Object
  extended by com.stratelia.silverpeas.silvertrace.SilverLog

public class SilverLog
extends Object

SilverLog is the trace tool used in silverpeas to log the users' connexions. This is a 'fully' static class. All functions could be called directly and is thread-safe. The log function is : log.

Author:
Marc Guillemin

Field Summary
static int APPENDER_ALL
          Used to remove all appenders attached to this module
static int APPENDER_CONSOLE
          Appender sending informations on console
static int APPENDER_FILE
          Appender sending informations on file
static int APPENDER_MAIL
          Appender sending informations mail
static int APPENDER_ROLLING_FILE
          Appender sending informations on rolling file
protected static org.apache.log4j.Logger currentLogger
           
static String LAYOUT_DETAILED
          Detailed layout : Display "Time / Priority / Calling Class and module / Message"
static String LAYOUT_FULL_DEBUG
          Fully detailed layout : Display "Tic count / Time / Priority / Thread / Calling Class and module / Message"
static String LAYOUT_HTML
          HTML layout : Display "Time / Thread / Priority / Category / Message" into a TABLE
static String LAYOUT_SHORT
          Short layout : Display "Time / Priority / Message"
protected static String layoutDetailed
           
protected static String layoutFullDebug
           
protected static String layoutShort
           
protected static String logDir
           
protected static String logModule
           
static String ROLLING_MODE_DAILY
          The trace file will be copied every day at midnight with the name : FileName.ext.year-mounth-day A new file named FileName.ext is the created and will contains the next day's traces Example : MyFile.txt.2001-07-23
static String ROLLING_MODE_HOUR
          The trace file will be copied every hour with the name : FileName.ext.year-mounth-day-hour A new file named FileName.ext is the created and will contains the next hour's traces Example : MyFile.txt.2001-07-23-18
static String ROLLING_MODE_MOUNTH
          The trace file will be copied every 1st day of a mounth with the name : FileName.ext.year-mounth A new file named FileName.ext is the created and will contains the next mounth's traces Example : MyFile.txt.2001-07
static String ROLLING_MODE_WEEK
          The trace file will be copied every 1st day of a week with the name : FileName.ext.year-week A new file named FileName.ext is the created and will contains the next week's traces Example : MyFile.txt.2001-34
static int TRACE_LEVEL_DEBUG
          Debug-level traces
static int TRACE_LEVEL_ERROR
          Error-level traces
static int TRACE_LEVEL_FATAL
          Fatal-level traces
static int TRACE_LEVEL_INFO
          Info-level traces
static int TRACE_LEVEL_UNKNOWN
          Used in setTraceLevel to reset a level trace
static int TRACE_LEVEL_WARN
          Warning-level traces
 
Constructor Summary
SilverLog()
           
 
Method Summary
protected static void addAppenderConsole(String patternLayout, String consoleName)
          Add a new console appender.
protected static void addAppenderFile(String patternLayout, String fileName, boolean appendOnFile)
          Add a new file appender.
protected static void addAppenderFromBundle(ResourceBundle resource, int appenderNumber, int appenderType)
          Read appender information from a property file and attach it to it's module
protected static void addAppenderMail(String patternLayout, String mailHost, String mailFrom, String mailTo, String mailSubject)
          Add a new mail appender.
protected static void addAppenderRollingFile(String patternLayout, String fileName, String rollingMode)
          Add a new rolling file appender.
protected static String formatTraceMessage(String message, String adresseIP, String userLogin)
          Format the trace message to send to log4j
protected static String getAppenderName(int typeOfAppender)
          Return the name of the appender depending on it's attached module and type
protected static org.apache.log4j.Layout getLayout(String patternLayout)
          Return the layout object depending on it's name
protected static void initAll()
          Init all appenders
static void initFromBundle(ResourceBundle resource)
          Loads the configuration from the resource given in argument.
static void logConnexion(String message, String ipAddress, String userLogin)
          Log connexion informations.
protected static void removeAppender(int typeOfAppender)
          Remove appender(s). typeOfAppender could be one value or a mask of multiple appender types
protected static String translateFileName(String fileName)
          Translate the @ErrorDir@ into the real value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACE_LEVEL_UNKNOWN

public static final int TRACE_LEVEL_UNKNOWN
Used in setTraceLevel to reset a level trace

See Also:
Constant Field Values

TRACE_LEVEL_DEBUG

public static final int TRACE_LEVEL_DEBUG
Debug-level traces

See Also:
Constant Field Values

TRACE_LEVEL_INFO

public static final int TRACE_LEVEL_INFO
Info-level traces

See Also:
Constant Field Values

TRACE_LEVEL_WARN

public static final int TRACE_LEVEL_WARN
Warning-level traces

See Also:
Constant Field Values

TRACE_LEVEL_ERROR

public static final int TRACE_LEVEL_ERROR
Error-level traces

See Also:
Constant Field Values

TRACE_LEVEL_FATAL

public static final int TRACE_LEVEL_FATAL
Fatal-level traces

See Also:
Constant Field Values

APPENDER_CONSOLE

public static final int APPENDER_CONSOLE
Appender sending informations on console

See Also:
addAppenderConsole(java.lang.String, java.lang.String), removeAppender(int), Constant Field Values

APPENDER_FILE

public static final int APPENDER_FILE
Appender sending informations on file

See Also:
addAppenderFile(java.lang.String, java.lang.String, boolean), removeAppender(int), Constant Field Values

APPENDER_ROLLING_FILE

public static final int APPENDER_ROLLING_FILE
Appender sending informations on rolling file

See Also:
addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), removeAppender(int), ROLLING_MODE_MOUNTH, ROLLING_MODE_WEEK, ROLLING_MODE_DAILY, ROLLING_MODE_HOUR, Constant Field Values

APPENDER_MAIL

public static final int APPENDER_MAIL
Appender sending informations mail

See Also:
addAppenderMail(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), removeAppender(int), Constant Field Values

APPENDER_ALL

public static final int APPENDER_ALL
Used to remove all appenders attached to this module

See Also:
removeAppender(int), Constant Field Values

LAYOUT_HTML

public static final String LAYOUT_HTML
HTML layout : Display "Time / Thread / Priority / Category / Message" into a TABLE

See Also:
addAppenderConsole(java.lang.String, java.lang.String), addAppenderFile(java.lang.String, java.lang.String, boolean), addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), addAppenderMail(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), Constant Field Values

LAYOUT_SHORT

public static final String LAYOUT_SHORT
Short layout : Display "Time / Priority / Message"

See Also:
addAppenderConsole(java.lang.String, java.lang.String), addAppenderFile(java.lang.String, java.lang.String, boolean), addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), addAppenderMail(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), Constant Field Values

LAYOUT_DETAILED

public static final String LAYOUT_DETAILED
Detailed layout : Display "Time / Priority / Calling Class and module / Message"

See Also:
addAppenderConsole(java.lang.String, java.lang.String), addAppenderFile(java.lang.String, java.lang.String, boolean), addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), addAppenderMail(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), Constant Field Values

LAYOUT_FULL_DEBUG

public static final String LAYOUT_FULL_DEBUG
Fully detailed layout : Display "Tic count / Time / Priority / Thread / Calling Class and module / Message"

See Also:
addAppenderConsole(java.lang.String, java.lang.String), addAppenderFile(java.lang.String, java.lang.String, boolean), addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), addAppenderMail(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), Constant Field Values

ROLLING_MODE_MOUNTH

public static final String ROLLING_MODE_MOUNTH
The trace file will be copied every 1st day of a mounth with the name : FileName.ext.year-mounth A new file named FileName.ext is the created and will contains the next mounth's traces Example : MyFile.txt.2001-07

See Also:
addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), Constant Field Values

ROLLING_MODE_WEEK

public static final String ROLLING_MODE_WEEK
The trace file will be copied every 1st day of a week with the name : FileName.ext.year-week A new file named FileName.ext is the created and will contains the next week's traces Example : MyFile.txt.2001-34

See Also:
addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), Constant Field Values

ROLLING_MODE_DAILY

public static final String ROLLING_MODE_DAILY
The trace file will be copied every day at midnight with the name : FileName.ext.year-mounth-day A new file named FileName.ext is the created and will contains the next day's traces Example : MyFile.txt.2001-07-23

See Also:
addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), Constant Field Values

ROLLING_MODE_HOUR

public static final String ROLLING_MODE_HOUR
The trace file will be copied every hour with the name : FileName.ext.year-mounth-day-hour A new file named FileName.ext is the created and will contains the next hour's traces Example : MyFile.txt.2001-07-23-18

See Also:
addAppenderRollingFile(java.lang.String, java.lang.String, java.lang.String), Constant Field Values

currentLogger

protected static org.apache.log4j.Logger currentLogger

logDir

protected static String logDir

logModule

protected static String logModule

layoutShort

protected static final String layoutShort
See Also:
Constant Field Values

layoutDetailed

protected static final String layoutDetailed
See Also:
Constant Field Values

layoutFullDebug

protected static final String layoutFullDebug
See Also:
Constant Field Values
Constructor Detail

SilverLog

public SilverLog()
Method Detail

logConnexion

public static void logConnexion(String message,
                                String ipAddress,
                                String userLogin)
Log connexion informations.

Parameters:
message - login/logout
ipAddress - of the connected client
userLogin - of the connected client

initAll

protected static void initAll()
Init all appenders


initFromBundle

public static void initFromBundle(ResourceBundle resource)
Loads the configuration from the resource given in argument.

Parameters:
resource - the properties to merge with the current configuration

addAppenderFromBundle

protected static void addAppenderFromBundle(ResourceBundle resource,
                                            int appenderNumber,
                                            int appenderType)
Read appender information from a property file and attach it to it's module

Parameters:
resource -
appenderNumber -
appenderType -

addAppenderConsole

protected static void addAppenderConsole(String patternLayout,
                                         String consoleName)
Add a new console appender. If an appender with the same type have been previously set, delete it and replace it with the new created one.

Parameters:
patternLayout - the things displayed in this appender, could be one of the LAYOUT_... constants
consoleName - Name of the console output. If null or "", "system.out" is used

addAppenderFile

protected static void addAppenderFile(String patternLayout,
                                      String fileName,
                                      boolean appendOnFile)
Add a new file appender. If an appender with the same type have been previously set, delete it and replace it with the new created one.

Parameters:
patternLayout - the things displayed in this appender, could be one of the LAYOUT_... constants
fileName - full-path name of the file where the trace are written
appendOnFile - true to append at the end of the existing file (if ther is one), false to remove old file before writting

addAppenderRollingFile

protected static void addAppenderRollingFile(String patternLayout,
                                             String fileName,
                                             String rollingMode)
Add a new rolling file appender. If an appender with the same type have been previously set, delete it and replace it with the new created one.

Parameters:
patternLayout - the things displayed in this appender, could be one of the LAYOUT_... constants
fileName - full-path name of the file where the trace are written
rollingMode - frequency of the rolling file, could be one of the ROLLING_MODE_... constants

addAppenderMail

protected static void addAppenderMail(String patternLayout,
                                      String mailHost,
                                      String mailFrom,
                                      String mailTo,
                                      String mailSubject)
Add a new mail appender. If an appender with the same type have been previously set, delete it and replace it with the new created one. How it works : mails are only sent when an ERROR or FATAL occur. The mail contains the error and the 512 last traces taken into account (ie, higher than the trace level).

Parameters:
patternLayout - the things displayed in this appender, could be one of the LAYOUT_... constants
mailHost - host name
mailFrom - email of the sender
mailTo - target email, could be multiple targets separeted with comas
mailSubject - subject of the mail

removeAppender

protected static void removeAppender(int typeOfAppender)
Remove appender(s). typeOfAppender could be one value or a mask of multiple appender types

Parameters:
typeOfAppender - could be a mask of APPENDER_... values or APPENDER_ALL to remove all appenders attached to the module

formatTraceMessage

protected static String formatTraceMessage(String message,
                                           String adresseIP,
                                           String userLogin)
Format the trace message to send to log4j

Returns:
the built message

translateFileName

protected static String translateFileName(String fileName)
Translate the @ErrorDir@ into the real value

Parameters:
fileName -

getLayout

protected static org.apache.log4j.Layout getLayout(String patternLayout)
Return the layout object depending on it's name

Parameters:
patternLayout -
Returns:

getAppenderName

protected static String getAppenderName(int typeOfAppender)
Return the name of the appender depending on it's attached module and type

Parameters:
typeOfAppender -
Returns:


Copyright © 2016 Silverpeas. All Rights Reserved.