org.mondemand

Class Client


public class Client
extends java.lang.Object

This is the main entry point to MonDemand. Users can create client objects and use them to log messages and statistics.
Author:
Michael Lum

Constructor Summary

Client(String programId)
The constructor creates a Client object that is ready to use.

Method Summary

void
addContext(String key, String value)
Adds contextual data to the client.
void
addTransport(Transport transport)
Adds a new transport to this client.
void
alert(String message)
A convenience method to log a message at priority level ALERT
void
alert(String name, int line, TraceId traceId, String message, Object[] args)
Logs a message a priority level ALERT.
void
alert(TraceId traceId, String message, Object[] args)
Logs a message a priority level ALERT, determining the calling class and line number on the fly.
void
crit(String message)
A convenience method to log a message at priority level CRIT
void
crit(String name, int line, TraceId traceId, String message, Object[] args)
Logs a message at priority level CRIT
void
crit(TraceId traceId, String message, Object[] args)
Logs a message a priority level CRIT, determining the calling class and line number on the fly.
void
debug(String message)
A convenience method to log a message at priority level DEBUG
void
debug(String name, int line, TraceId traceId, String message, Object[] args)
Logs a message at priority level DEBUG
void
debug(TraceId traceId, String message, Object[] args)
Logs a message a priority level DEBUG, determining the calling class and line number on the fly.
void
decrement()
Decrements the default counter by one.
void
decrement(String key)
Decrements the specified counter by one.
void
decrement(String key, int value)
Decrements the specified counter by the value specified.
void
decrement(int value)
Decrements the default counter by value
void
emerg(String message)
A convenience method to log a message a log level EMERG.
void
emerg(String name, int line, TraceId traceId, String message, Object[] args)
Logs a message at priority level EMERG
void
emerg(TraceId traceId, String message, Object[] args)
Logs a message a priority level EMERG, determining the calling class and line number on the fly.
void
error(String message)
A convenience method to log a message at priority level ERROR
void
error(String name, int line, TraceId traceId, String message, Object[] args)
Logs a message at priority level ERROR
void
error(TraceId traceId, String message, Object[] args)
Logs a message a priority level ERROR, determining the calling class and line number on the fly.
void
finalize()
Called when the client is destroyed.
void
flush()
void
flushLogs()
Flushes log data to the transports.
void
flushStats()
Flushes statistics to the transports.
void
flushStats(boolean reset)
Flushes statistics to the transports, but allows one to specify whether or not to reset the running statistics.
String
getContext(String key)
Fetches contextual data from the client.
Enumeration
getContextKeys()
Retrieves an enumeration of all the contextual data keys
ErrorHandler
getErrorHandler()
int
getImmediateSendLevel()
int
getNoSendLevel()
String
getProgramId()
void
increment()
Increments the default counter by one.
void
increment(String key)
Increments the specified counter by one.
void
increment(String key, int value)
Increments the specified counter by the value specified.
void
increment(int value)
Increments the default counter by value
void
info(String message)
A convenience method to log a message at priority level INFO
void
info(String name, int line, TraceId traceId, String message, Object[] args)
Logs a message at priority level INFO
void
info(TraceId traceId, String message, Object[] args)
Logs a message a priority level INFO, determining the calling class and line number on the fly.
boolean
levelIsEnabled(int level, TraceId traceId)
A check for the log level that is set.
void
log(String name, int line, int level, TraceId traceId, String message, Object[] args)
The most generic logger function.
void
log(int level, TraceId traceId, String message, Object[] args)
Generic logger function.
void
notice(String message)
A convenience method to log a message at priority level NOTICE
void
notice(String name, int line, TraceId traceId, String message, Object[] args)
Logs a message at priority level NOTICE
void
notice(TraceId traceId, String message, Object[] args)
Logs a message a priority level NOTICE, determining the calling class and line number on the fly.
void
removeAllContexts()
Clear contextual data from the logger.
void
removeContext(String key)
Removes contextual data from the client.
void
setErrorHandler(ErrorHandler errorHandler)
Sets a custom error handler.
void
setImmediateSendLevel(int immediateSendLevel)
void
setKey(String key, int value)
Sets the counter to the specified val ue.
void
setKey(String key, long value)
Sets the counter to the specified val ue.
void
setNoSendLevel(int noSendLevel)
void
setProgramId(String programId)
void
warning(String message)
A convenience method to log a message at priority level WARNING
void
warning(String name, int line, TraceId traceId, String message, Object[] args)
Logs a message at priority level WARNING
void
warning(TraceId traceId, String message, Object[] args)
Logs a message a priority level WARNING, determining the calling class and line number on the fly.

Constructor Details

Client

public Client(String programId)
The constructor creates a Client object that is ready to use.
Parameters:
programId - a string identifying the program that is calling MonDemand

Method Details

addContext

public void addContext(String key,
                       String value)
Adds contextual data to the client.

addTransport

public void addTransport(Transport transport)
Adds a new transport to this client.
Parameters:
transport - the transport object to add

alert

public void alert(String message)
A convenience method to log a message at priority level ALERT
Parameters:
message - the log message

alert

public void alert(String name,
                  int line,
                  TraceId traceId,
                  String message,
                  Object[] args)
Logs a message a priority level ALERT.
Parameters:
name - the name of the calling class or filename
line - the line number of the calling class or filename
traceId - an optional trace ID
message - the log message
args - optional arguments

alert

public void alert(TraceId traceId,
                  String message,
                  Object[] args)
Logs a message a priority level ALERT, determining the calling class and line number on the fly.
Parameters:
traceId - an optional trace ID
message - the log message
args - optional arguments

crit

public void crit(String message)
A convenience method to log a message at priority level CRIT
Parameters:
message - the log message

crit

public void crit(String name,
                 int line,
                 TraceId traceId,
                 String message,
                 Object[] args)
Logs a message at priority level CRIT
Parameters:
name - the name of the calling class or filename
line - the line number of the calling class or filename
traceId - an optional trace ID
message - the log message
args - optional arguments

crit

public void crit(TraceId traceId,
                 String message,
                 Object[] args)
Logs a message a priority level CRIT, determining the calling class and line number on the fly.
Parameters:
traceId - an optional trace ID
message - the log message
args - optional arguments

debug

public void debug(String message)
A convenience method to log a message at priority level DEBUG
Parameters:
message - the log message

debug

public void debug(String name,
                  int line,
                  TraceId traceId,
                  String message,
                  Object[] args)
Logs a message at priority level DEBUG
Parameters:
name - the name of the calling class or filename
line - the line number of the calling class or filename
traceId - an optional trace ID
message - the log message
args - optional arguments

debug

public void debug(TraceId traceId,
                  String message,
                  Object[] args)
Logs a message a priority level DEBUG, determining the calling class and line number on the fly.
Parameters:
traceId - an optional trace ID
message - the log message
args - optional arguments

decrement

public void decrement()
Decrements the default counter by one.

decrement

public void decrement(String key)
Decrements the specified counter by one.
Parameters:
key - the name of the counter to decrement

decrement

public void decrement(String key,
                      int value)
Decrements the specified counter by the value specified.
Parameters:
key - the name of the counter to decrement
value - the amount to decrement the counter by

decrement

public void decrement(int value)
Decrements the default counter by value
Parameters:
value - the amount to decrement the counter by

emerg

public void emerg(String message)
A convenience method to log a message a log level EMERG.
Parameters:
message -

emerg

public void emerg(String name,
                  int line,
                  TraceId traceId,
                  String message,
                  Object[] args)
Logs a message at priority level EMERG
Parameters:
name - the name of the calling class or filename
line - the line number of the calling class or filename
traceId - an optional trace ID
message - the log message
args - optional arguments

emerg

public void emerg(TraceId traceId,
                  String message,
                  Object[] args)
Logs a message a priority level EMERG, determining the calling class and line number on the fly.
Parameters:
traceId - an optional trace ID
message - the log message
args - optional arguments

error

public void error(String message)
A convenience method to log a message at priority level ERROR
Parameters:
message - the log message

error

public void error(String name,
                  int line,
                  TraceId traceId,
                  String message,
                  Object[] args)
Logs a message at priority level ERROR
Parameters:
name - the name of the calling class or filename
line - the line number of the calling class or filename
traceId - an optional trace ID
message - the log message
args - optional arguments

error

public void error(TraceId traceId,
                  String message,
                  Object[] args)
Logs a message a priority level ERROR, determining the calling class and line number on the fly.
Parameters:
traceId - an optional trace ID
message - the log message
args - optional arguments

finalize

public void finalize()
Called when the client is destroyed. Ensures that everything is cleaned up properly.

flush

public void flush()

flushLogs

public void flushLogs()
Flushes log data to the transports.

flushStats

public void flushStats()
Flushes statistics to the transports.

flushStats

public void flushStats(boolean reset)
Flushes statistics to the transports, but allows one to specify whether or not to reset the running statistics.

getContext

public String getContext(String key)
Fetches contextual data from the client.

getContextKeys

public Enumeration getContextKeys()
Retrieves an enumeration of all the contextual data keys
Returns:
an enumeration of all keys

getErrorHandler

public ErrorHandler getErrorHandler()
Returns:
the errorHandler

getImmediateSendLevel

public int getImmediateSendLevel()
Returns:
the immediateSendLevel

getNoSendLevel

public int getNoSendLevel()
Returns:
the noSendLevel

getProgramId

public String getProgramId()
Returns:
the programId

increment

public void increment()
Increments the default counter by one.

increment

public void increment(String key)
Increments the specified counter by one.
Parameters:
key - the name of the counter to increment

increment

public void increment(String key,
                      int value)
Increments the specified counter by the value specified.
Parameters:
key - the name of the counter to increment
value - the amount to increment the counter by

increment

public void increment(int value)
Increments the default counter by value
Parameters:
value - the amount to increment the counter by

info

public void info(String message)
A convenience method to log a message at priority level INFO
Parameters:
message - the log message

info

public void info(String name,
                 int line,
                 TraceId traceId,
                 String message,
                 Object[] args)
Logs a message at priority level INFO
Parameters:
name - the name of the calling class or filename
line - the line number of the calling class or filename
traceId - an optional trace ID
message - the log message
args - optional arguments

info

public void info(TraceId traceId,
                 String message,
                 Object[] args)
Logs a message a priority level INFO, determining the calling class and line number on the fly.
Parameters:
traceId - an optional trace ID
message - the log message
args - optional arguments

levelIsEnabled

public boolean levelIsEnabled(int level,
                              TraceId traceId)
A check for the log level that is set.
Parameters:
level - the priority level to check
traceId - the TraceId to check for
Returns:
true if this level is enabled, false otherwise

log

public void log(String name,
                int line,
                int level,
                TraceId traceId,
                String message,
                Object[] args)
The most generic logger function.
Parameters:
name - the name of this message, usually the filename or calling class
line - the line number calling this message, or other numeric description of the calling class
level - the log level
traceId - an optional traceId
message - the message
args - optional arguments

log

public void log(int level,
                TraceId traceId,
                String message,
                Object[] args)
Generic logger function. This method will perform slower than most because it needs to detect the calling class and calling line number.
Parameters:
level - the log level of this message
traceId - an optional traceId
message - the log message
args - optional arguments

notice

public void notice(String message)
A convenience method to log a message at priority level NOTICE
Parameters:
message - the log message

notice

public void notice(String name,
                   int line,
                   TraceId traceId,
                   String message,
                   Object[] args)
Logs a message at priority level NOTICE
Parameters:
name - the name of the calling class or filename
line - the line number of the calling class or filename
traceId - an optional trace ID
message - the log message
args - optional arguments

notice

public void notice(TraceId traceId,
                   String message,
                   Object[] args)
Logs a message a priority level NOTICE, determining the calling class and line number on the fly.
Parameters:
traceId - an optional trace ID
message - the log message
args - optional arguments

removeAllContexts

public void removeAllContexts()
Clear contextual data from the logger. Contextual data persists between flush() calls and is only removed if you call removeAllContexts().

removeContext

public void removeContext(String key)
Removes contextual data from the client.

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
Sets a custom error handler. Cowardly refuses to set it to null.
Parameters:
errorHandler - the errorHandler to set

setImmediateSendLevel

public void setImmediateSendLevel(int immediateSendLevel)
Parameters:
immediateSendLevel - the immediateSendLevel to set

setKey

public void setKey(String key,
                   int value)
Sets the counter to the specified val ue.
Parameters:
key - the name of the counter key to set
value - the value to set this counter to

setKey

public void setKey(String key,
                   long value)
Sets the counter to the specified val ue.
Parameters:
key - the name of the counter key to set
value - the value to set this counter to

setNoSendLevel

public void setNoSendLevel(int noSendLevel)
Parameters:
noSendLevel - the noSendLevel to set

setProgramId

public void setProgramId(String programId)
Parameters:
programId - the programId to set

warning

public void warning(String message)
A convenience method to log a message at priority level WARNING
Parameters:
message - the log message

warning

public void warning(String name,
                    int line,
                    TraceId traceId,
                    String message,
                    Object[] args)
Logs a message at priority level WARNING
Parameters:
name - the name of the calling class or filename
line - the line number of the calling class or filename
traceId - an optional trace ID
message - the log message
args - optional arguments

warning

public void warning(TraceId traceId,
                    String message,
                    Object[] args)
Logs a message a priority level WARNING, determining the calling class and line number on the fly.
Parameters:
traceId - an optional trace ID
message - the log message
args - optional arguments