CADI.Common.Log
Class CADILog

java.lang.Object
  extended by CADI.Common.Log.CADILog

public class CADILog
extends java.lang.Object

This class provides a wrapper for abstracting the destination and format of the logs. The destination (standard output or file) and the format (plain text or XML) are selected in the constructor. In addittion, four log types are available: logDebug(String), logInfo(String), logWarning(String), logError(String).

Usage example:
  construct
  logInfo or logWarning or logError or logDebug methods

Version:
1.0.2 2008/09/21
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  int count
          Indicates the number of files to use.
private  boolean enabled
          Indicate whether logs are or not enabled.
private  java.util.logging.FileHandler fileHandler
           
private  java.lang.String fileName
          Is the file name where logs are done.
static int LEVEL_DEBUG
           
static int LEVEL_ERROR
           
static int LEVEL_INFO
           
static int LEVEL_WARNING
           
private  int limit
          Indicates the maximum number of bytes to write in any file.
private  java.util.logging.Logger logger
           
private  int logLevel
          Indicates which is the severity of the messages that it will record.
private  boolean logToFile
          Indicates whether logs are saved in a file or they are printed in the standard output.
private  java.io.OutputStream outputStream
           
private  java.util.logging.StreamHandler streamHandler
           
private  boolean useXMLFormat
          Indicates if XML format is used to create the log file.
 
Constructor Summary
CADILog()
          Constructor.
CADILog(java.lang.String fileName, boolean useXMLFormat)
          Constructor.
 
Method Summary
 void close()
          Closes the log.
 void configure(java.lang.String fileName, boolean useXMLFormat)
          Configures the file name and log format parameters.
private  void flush()
          Flush any buffered messages.
 java.lang.String getFileName()
          Returns the fileName attribute.
 int getLogLevel()
          Retuns the logLevel attribute.
 boolean isEnabled()
          Checks whether the logs are enabled.
 void list(java.io.PrintStream out)
          Prints this CADI Log fields out to the specified output stream.
 void logDebug(java.lang.String str)
          Method used to the DEBUG logs.
 void logError(java.lang.String str)
          Method used to the ERROR logs.
 void logInfo(java.lang.String str)
          Method used to the INFO logs.
 void logWarning(java.lang.String str)
          Method used to the WARNING logs.
 void setEnabled(boolean enabled)
          Sets the log enabled or disabled.
 void setLogLevel(int logLevel)
          Sets the logLevel attribute.
 void setParameters(java.lang.String fileName, boolean useXMLFormat)
          Sets the file name and log format parameters.
 java.lang.String toString()
           
 boolean useXMLFormat()
          Checks whether data are logged using plain text or XML format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

enabled

private boolean enabled
Indicate whether logs are or not enabled.


useXMLFormat

private boolean useXMLFormat
Indicates if XML format is used to create the log file. If XML format is not setted, simple format is used.

Default value: false (simple format is used)


logToFile

private boolean logToFile
Indicates whether logs are saved in a file or they are printed in the standard output.


fileName

private java.lang.String fileName
Is the file name where logs are done. If null logs are printed out in the standard output.


logLevel

private int logLevel
Indicates which is the severity of the messages that it will record. Log messages are recorded only if the message level is greater than or equal to the logLevel attribute.

Allowed values: LEVEL_DEBUG, LEVEL_INFO, LEVEL_INFO and, LEVEL_ERROR.


LEVEL_DEBUG

public static final int LEVEL_DEBUG
See Also:
Constant Field Values

LEVEL_INFO

public static final int LEVEL_INFO
See Also:
Constant Field Values

LEVEL_WARNING

public static final int LEVEL_WARNING
See Also:
Constant Field Values

LEVEL_ERROR

public static final int LEVEL_ERROR
See Also:
Constant Field Values

logger

private java.util.logging.Logger logger

fileHandler

private java.util.logging.FileHandler fileHandler

streamHandler

private java.util.logging.StreamHandler streamHandler

outputStream

private java.io.OutputStream outputStream

limit

private int limit
Indicates the maximum number of bytes to write in any file.


count

private int count
Indicates the number of files to use.

Constructor Detail

CADILog

public CADILog()
Constructor.


CADILog

public CADILog(java.lang.String fileName,
               boolean useXMLFormat)
Constructor.

Parameters:
fileName - the file name where logs are writen. If it is null, logs are displayed in the standard ouptut.
useXMLFormat - if true, logs are formated using XML format. Otherwise, standard format is used.
Method Detail

setParameters

public void setParameters(java.lang.String fileName,
                          boolean useXMLFormat)
Sets the file name and log format parameters.

Parameters:
fileName - the file name where logs are writen. If it is null, logs are displayed in the standard ouptut.
useXMLFormat - if true, logs are formated using XML format. Otherwise, standard format is used.

logDebug

public void logDebug(java.lang.String str)
Method used to the DEBUG logs.

Parameters:
str - the string message.

logInfo

public void logInfo(java.lang.String str)
Method used to the INFO logs.

Parameters:
str - the string message.

logWarning

public void logWarning(java.lang.String str)
Method used to the WARNING logs.

Parameters:
str - the string message.

logError

public void logError(java.lang.String str)
Method used to the ERROR logs.

Parameters:
str - the string message.

setEnabled

public void setEnabled(boolean enabled)
Sets the log enabled or disabled.

Parameters:
enabled - if true, logs are enabled. Otherwise, logs are disabled.

setLogLevel

public void setLogLevel(int logLevel)
Sets the logLevel attribute.

Parameters:
logLevel - see logLevel attribute.

close

public void close()
Closes the log.


isEnabled

public boolean isEnabled()
Checks whether the logs are enabled.

Returns:
true if the logs are enabled.

useXMLFormat

public boolean useXMLFormat()
Checks whether data are logged using plain text or XML format.

Returns:
true if data log format is XML. Otherwise, returns false.

getFileName

public java.lang.String getFileName()
Returns the fileName attribute.

Returns:
the fileName attribue.

getLogLevel

public int getLogLevel()
Retuns the logLevel attribute.

Returns:
the logLevel attribute.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

list

public void list(java.io.PrintStream out)
Prints this CADI Log fields out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

configure

public void configure(java.lang.String fileName,
                      boolean useXMLFormat)
Configures the file name and log format parameters.

Parameters:
fileName - the file name where logs are writen. If it is null, logs are displayed in the standard ouptut.
useXMLFormat - if true, logs are formated using XML format. Otherwise, standard format is used.

flush

private void flush()
Flush any buffered messages.



CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)