Logging in Marauroa

From Arianne
Jump to navigation Jump to search

Writing to log files or a terminal window is a low technology way of working out what your code is doing; you may also write to log files on key events to give a historical record or audit trail. The log4j package provides logging capabilities for Java programs. This page gives a quick overview of log4j, and a summary of how and where it is used in Marauroa. For more details see the [log4j home site].

Summary

The simple description is that when writing code, a logger object is created in each class definition where logging is required. Each logger has several methods that relate to the importance (level) of a message to be logged. These are TRACE < DEBUG < INFO < WARN < ERROR < FATAL with TRACE being the lowest priority and FATAL the highest. A example might be:

    logger.warn("This is a warning message");

The behaviour of the logging is controlled by a configuration file. This specifies:

  • The default (root) logging level and any output stream names (appenders)

For each appender:

  • The type of appender, i.e. the output stream, e.g.
    • ConsoleAppender, FileAppender, RollingFileAppender (and others)
  • The format of the output
    • PatternLayout, XMLLayout
  • Any format specifiers, e.g. the layout of a pattern

For each class containing a logger (optional):

  • The logger class and minimum level of message that will be logged, using the levels given above plus ALL and OFF. If a class is not listed it will use the root level specified above.

A sample configuration file might look like:

# Set root logger level to INFO and its only appender to A1.
log4j.rootLogger=INFO, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Specify Configuration at runtime

Add the following parameters to the java command line when starting your program.

-Dlog4j.configuration="file:/C:/my/folder/log4j.properties"

-Dlog4j.debug

Marauroa

Current logging in Marauroa (assorted information) is listed below. Marauroa uses a wrapper class that would allow the log4j package to be removed, meaning the wrapper package is referenced in the main code. A few exceptions are given below.

Logging in Marauroa
Used in Class filename Modifiers Logger Type Logger name Class name / parameter
AbstractDatabaseAdapter private static Logger logger
AccountDAO private static final marauroa.common.Logger logger
ActionHandler private static final marauroa.common.Logger logger
AdapterFactory private static Logger logger
Attributes private static Logger logger
BanListDAO private static Logger logger
CharacterDAO private static final marauroa.common.Logger logger
ChooseCharacterHandler private static final marauroa.common.Logger logger
ClientFramework private static final marauroa.common.Logger logger
Configuration private static final marauroa.common.Logger logger
ConnectionValidator private static final marauroa.common.Logger logger
CreateAccountHandler private static final marauroa.common.Logger logger
CreateCharacterHandler private static final marauroa.common.Logger logger
DatabaseFactory private static final marauroa.common.Logger logger
DBCommandQueueBackgroundThread private static Logger logger
DBTransaction private static Logger logger
Decoder private static final marauroa.common.Logger logger
Definition private static final marauroa.common.Logger logger
DelayedEventHandlerThread private static final marauroa.common.Logger logger
DisconnectHandler private static final marauroa.common.Logger logger
FloodCheck private static final marauroa.common.Logger logger
FloodValidator private static final marauroa.common.Logger logger
GameEventDAO private static final marauroa.common.Logger logger
GameServerManager private static final marauroa.common.Logger logger
H2DatabaseAdapter private static Logger logger MySQLDatabaseAdapter
Hash private static Logger logger
JDBCSQLHelper private static final marauroa.common.Logger logger
KeepAliveHandler private static final marauroa.common.Logger logger
LinkedRPObjectList private static final Logger logger
LoadActiveCharacterCommand private static Logger logger
LoginEventDAO private static final marauroa.common.Logger logger
LoginRequestKeyHandler private static final marauroa.common.Logger logger
LoginSeedDAO private static final marauroa.common.Logger logger
LoginSendPromiseHandler private static final marauroa.common.Logger logger
LogoutHandler private static final marauroa.common.Logger logger
marauroad private static final Logger logger
marauroad private final Logger log
MarauroaRPZone private static final marauroa.common.Logger logger
MarauroaUncaughtExceptionHandler private static Logger logger
MessageDispatcher private static final marauroa.common.Logger logger
MessageFactory private static final marauroa.common.Logger logger Attributes
MessageHandler private static final marauroa.common.Logger logger
MessageS2CCreateAccountNACK private static Logger logger
MessageS2CCreateCharacterNACK private static Logger logger MessageS2CCreateAccountNACK
MySQLDatabaseAdapter private static Logger logger
NetConst private static final marauroa.common.Logger logger
NioServer private static final marauroa.common.Logger logger
OutOfSyncHandler private static final marauroa.common.Logger logger
PerceptionHandler private static final marauroa.common.Logger logger
Persistence private final static Logger logger
PlayerEntry private static Logger logger
PlayerEntry private static Logger logger SecuredLoginInfo
PlayerEntryContainer private static final marauroa.common.Logger logger
PythonRPWorld private static final marauroa.common.Logger logger
RPClass private static final marauroa.common.Logger logger
RPEvent private static final marauroa.common.Logger logger
RPObject private static final marauroa.common.Logger logger
RPObjectDAO private static final marauroa.common.Logger logger
RPObjectFactory private static final marauroa.common.Logger logger
RPRuleProcessorImpl private static Logger logger
RPScheduler private static final marauroa.common.Logger logger
RPServerManager private static final marauroa.common.Logger logger
RPSlot private static final marauroa.common.Logger logger RPObject
RPWorld private static final marauroa.common.Logger logger
RPZoneDAO private static final marauroa.common.Logger logger
RWLock private static final marauroa.common.Logger logger
SecuredLoginHandler private static final marauroa.common.Logger logger
SecuredLoginHandler private static Logger infoLogger ServerInfo
SlotOwner private static final marauroa.common.Logger logger
Statistics private static final marauroa.common.Logger logger
StatisticsDAO private static final marauroa.common.Logger logger
TransactionPool private static Logger logger
TransferACKHandler private static final marauroa.common.Logger logger
UnkownMessageHandler private static final marauroa.common.Logger logger
UpdateScript private static Logger logger
Validator private static Logger logger

Level of logging

Fatal - none

Error - 153 matches in 62 files

Warn - 76 matches in 34 files

Info - 45 matches in 18 files

Debug - 126 matches in 31 files

Log - none (method defined in Logger class)

Direct reference to Log4j

"import org.apache.log4j" is referred to in 4 files

NDC - 4 matches in 1 file

MDC - 4 matches in 2 files