org.mondemand
Class Client

java.lang.Object
  extended by org.mondemand.Client

public class Client
extends 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(int value)
          Decrements the default counter by value
 void decrement(StatType type, String key, int value)
           
 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 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<String> 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(int value)
          Increments the default counter by value
 void increment(StatType type, String key, int value)
           
 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 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(int level, TraceId traceId, String message, Object[] args)
          Generic logger function.
 void log(String name, int line, int level, TraceId traceId, String message, Object[] args)
          The most 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(StatType type, String key, long value)
           
 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)
           
 boolean traceMessage(String message, Map<String,String> context)
           
 boolean traceMessage(String owner, String traceId, String message, Map<String,String> context)
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

finalize

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

Overrides:
finalize in class Object

getProgramId

public String getProgramId()
Returns:
the programId

setProgramId

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

getImmediateSendLevel

public int getImmediateSendLevel()
Returns:
the immediateSendLevel

setImmediateSendLevel

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

getNoSendLevel

public int getNoSendLevel()
Returns:
the noSendLevel

setNoSendLevel

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

getErrorHandler

public ErrorHandler getErrorHandler()
Returns:
the errorHandler

setErrorHandler

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

Parameters:
errorHandler - the errorHandler to set

addContext

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


removeContext

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


getContext

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


getContextKeys

public Enumeration<String> getContextKeys()
Retrieves an enumeration of all the contextual data keys

Returns:
an enumeration of all keys

removeAllContexts

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


addTransport

public void addTransport(Transport transport)
Adds a new transport to this client.

Parameters:
transport - the transport object to add

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

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.


flush

public void flush()

increment

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


increment

public void increment(int value)
Increments the default counter by value

Parameters:
value - the amount to increment the counter by

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(StatType type,
                      String key,
                      int value)

decrement

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


decrement

public void decrement(int value)
Decrements the default counter by value

Parameters:
value - the amount to decrement the counter by

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(StatType type,
                      String key,
                      int value)

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

setKey

public void setKey(StatType type,
                   String key,
                   long value)

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

emerg

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

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

alert

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

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

crit

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

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

error

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

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

warning

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

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

notice

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

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

info

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

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

debug

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

Parameters:
message - the log message

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

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

traceMessage

public boolean traceMessage(String message,
                            Map<String,String> context)

traceMessage

public boolean traceMessage(String owner,
                            String traceId,
                            String message,
                            Map<String,String> context)


Copyright © 2012. All Rights Reserved.