|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlog.Log
Log is a very easy-to-use logging system, replacing efficiently "System.out.println()" debugging. Compared to the standard Logging class, or compared to the well known Log4J package, this one aims to follow Pareto's law: You will get 80% of the functionalities, but you will spend only 20% of your time. And most users even need less than 80%...
The fastest way to learn how to use this library is probably to study and test the two examples below:
import log.*; public class LogTest { public static void main(String[] args) { Log.log("Start of the program"); // logs a message with the default level, set by the setDefaultLevel() // method execute(); } private static void execute() { Log.enter(); // logs a method entry with the default level, set by the // setDefaultLevel() method Log.exit("I am quitting the execute() method"); // logs a method exit with the default level, set by the // setDefaultLevel() method, and adds the specified message } }
import log.*; import mess.*; public class LogTest2 { public static void main(String[] args) { Log.log("Start of the program"); // logs a message with the default level, set by the setDefaultLevel() // method Log.setFile("./mylogs/report.log"); // we want to record the logging information in a file called report.log // that is in the mylogs directory Log.setFileLevel(3); // logging instructions will be recorded in the file only if the level // is <= 3 (Log.INFO is a shortcut that worth 3) Log.setFileLevel("mess.Message", 4); // but for the mess.Message class, we define the level = 4 (Log.DEBUG is // a shortcut that worth 4) Log.setConsoleLevel(1); // in the console we want only very important logging information // (Log.SEVERE is a shortcut that worth 1) execute(); Message message = new Message("This is a message"); message.display(); } private static void execute() { Log.enter(); // logs a method entry with the default level, set by the // setDefaultLevel() method Log.exit("I am quitting the execute() method"); // logs a method exit with the default level, set by the // setDefaultLevel() method, and adds the specified message } } package mess; import log.*; public class Message { private String text; public Message(String text) { Log.enter("I am entering the constructor", 1); // logs a method entry with the specified level and adds the specified // message this.text = text; Log.exit(); // logs a method exit with the default level, set by the setDefaultLevel() // method } public void display() { Log.enter(1); // logs a method entry with the specified level Log.log("I am going to display a message", 1); // logs a message with the specified level System.out.println(text); Log.exit(1); // logs a method exit with the specified level } }
Field Summary | |
static int |
ALL
ALL is the maximum value for a message level. |
static int |
DEBUG
DEBUG is a message level used essentially during the debugging process. |
static int |
INFO
INFO is a message level that indicates an information. |
static int |
OFF
OFF is the minimum value for a message level. |
static int |
SEVERE
SEVERE is a message level that indicates a serious failure. |
static int |
WARNING
WARNING is a message level that indicates a warning. |
Method Summary | |
static void |
enter()
Logs a method entry according to the default levels. |
static void |
enter(int level)
Logs a method entry according to the specified level. |
static void |
enter(Object msg)
Logs a method entry according to the default levels, and adds the specified message. |
static void |
enter(Object msg,
int level)
Logs a method entry according to the specified level, and adds the specified message. |
static void |
exit()
Logs a method exit according to the default levels. |
static void |
exit(int level)
Logs a method exit according to the specified level. |
static void |
exit(Object msg)
Logs a method exit according to the default levels, and adds the specified message. |
static void |
exit(Object msg,
int level)
Logs a method exit according to the specified level, and adds the specified message. |
static void |
log(Object msg)
Logs the specified message according to the default levels. |
static void |
log(Object msg,
int level)
Logs the specified message according to the specified level. |
static void |
setConsoleLevel(int consoleLevel)
Sets the current console level. |
static void |
setConsoleLevel(String className,
int consoleLevel)
Sets the current console level for a specific class. |
static void |
setDefaultLevel(int defaultLevel)
Sets the default level value to use during a display operation for all the messages for whose the user did not specified a level. |
static void |
setFile(String filename)
Sets the file that records logging information. |
static void |
setFile(String filename,
int count)
Initialize a set of files that record logging information. |
static void |
setFileLevel(int fileLevel)
Sets the current file level. |
static void |
setFileLevel(String className,
int fileLevel)
Sets the current file level for a specific class. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int OFF
public static final int SEVERE
public static final int WARNING
public static final int INFO
public static final int DEBUG
public static final int ALL
Method Detail |
public static void setFile(String filename)
filename
- the filenamesetFile(String, int)
public static void setFile(String filename, int count)
filename
- the filenamecount
- the cyle (1 <= count <= 999)setFile(String)
public static void setConsoleLevel(int consoleLevel)
consoleLevel
- the current console levelsetConsoleLevel(String, int)
consoleLevel
is 3 (Log.INFO)public static void setConsoleLevel(String className, int consoleLevel)
setConsoleLevel(int consoleLevel)
method.
If the class is inside a package, the name must be fully specified, for
example: java.awt.Component. Note that once this method is used, the
logging process will have to check every time if the current class has or
not a specific level, which is a time consuming operation.
className
- the name of the class, with its packageconsoleLevel
- the current console level for this classsetConsoleLevel(int)
public static void setFileLevel(int fileLevel)
fileLevel
- the current file levelsetFileLevel(String, int)
fileLevel
is 3 (Log.INFO)public static void setFileLevel(String className, int fileLevel)
setFileLevel(int fileLevel)
method.
If the class is inside a package, the name must be fully specified, for
example: java.awt.Component. Note that once this method is used, the
logging process will have to check every time if the current class has or
not a specific level, which is a time consuming operation.
className
- the name of the class, with its packagefileLevel
- the current console level for this classsetFileLevel(int)
public static void setDefaultLevel(int defaultLevel)
defaultLevel
- the default leveldefaultLevel
is 3
(Log.INFO)public static void log(Object msg)
msg
- the messagepublic static void log(Object msg, int level)
msg
- the messagelevel
- the levelpublic static void enter()
public static void enter(int level)
level
- the levelpublic static void enter(Object msg)
msg
- the messagepublic static void enter(Object msg, int level)
msg
- the messagelevel
- the levelpublic static void exit()
public static void exit(int level)
level
- the levelpublic static void exit(Object msg)
msg
- the messagepublic static void exit(Object msg, int level)
msg
- the messagelevel
- the level
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |