HowTos Log Management
Aus Salespoint
(Unterschied zwischen Versionen)
(Die Seite wurde neu angelegt: „===Define a Log=== ===Define a new LogEntry=== ===Define a new LogEntryFilter=== ===Define a new ProcessLogEntry=== ===Implement the Interface Loggable=== ===...“) |
(→Define a Log) |
||
Zeile 1: | Zeile 1: | ||
===Define a Log=== | ===Define a Log=== | ||
+ | |||
+ | '''Description:''' | ||
+ | As described in [[#Understand logging]], a Log is the representation of the "log file", which only is a real file, if the specified OutputStream is the recommended FileOutputstream. | ||
+ | For a global Log, you only have to define a GlobalOutputStream by calling the static method Log.setGlobalLogOutputStream(OutputStream newOS). For local logging, you have to initialize a new instance of Log, either by using the constructor, the static method Log.createLog(OutputStream newOS) or a LogCreator. | ||
+ | |||
+ | '''ToDo:''' | ||
+ | |||
+ | # For the initialization find a place at the beginning of your application runtime to make sure, the LogOutputStream exists before any logging starts. | ||
+ | # Due to the new FileOutputStream, remember to catch the thrown IOException. | ||
+ | # Use the static method setGlobalOutputStream, which will initialize a new Log and a globally reachable OutputStream, enabling logging to it anywhere in your application. | ||
+ | |||
+ | '''Example Source Code:''' | ||
+ | <code java> | ||
+ | 1 | ||
+ | // within the main method, but may be anywhere before any logging starts | ||
+ | public static void main(String[] args) | ||
+ | { | ||
+ | LogShop logShop = new LogShop(); | ||
+ | Shop.setTheShop(logShop); | ||
+ | |||
+ | 2 | ||
+ | // remember to catch the possible IOException of creating a new FileOutputStream | ||
+ | try | ||
+ | { | ||
+ | 3 | ||
+ | // the static method will initialize a new Log and set the FileOutputStream global | ||
+ | // so it can be used anywhere in the application | ||
+ | Log.setGlobalOutputStream(new FileOutputStream("machine.log", true)); | ||
+ | } | ||
+ | catch(IOException ioException) | ||
+ | { | ||
+ | System.err.println("Unable to create log file."); | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
===Define a new LogEntry=== | ===Define a new LogEntry=== | ||
===Define a new LogEntryFilter=== | ===Define a new LogEntryFilter=== |
Version vom 22:20, 5. Apr. 2009
Inhaltsverzeichnis |
Define a Log
Description: As described in #Understand logging, a Log is the representation of the "log file", which only is a real file, if the specified OutputStream is the recommended FileOutputstream. For a global Log, you only have to define a GlobalOutputStream by calling the static method Log.setGlobalLogOutputStream(OutputStream newOS). For local logging, you have to initialize a new instance of Log, either by using the constructor, the static method Log.createLog(OutputStream newOS) or a LogCreator.
ToDo:
- For the initialization find a place at the beginning of your application runtime to make sure, the LogOutputStream exists before any logging starts.
- Due to the new FileOutputStream, remember to catch the thrown IOException.
- Use the static method setGlobalOutputStream, which will initialize a new Log and a globally reachable OutputStream, enabling logging to it anywhere in your application.
Example Source Code:
1
// within the main method, but may be anywhere before any logging starts
public static void main(String[] args)
{
LogShop logShop = new LogShop();
Shop.setTheShop(logShop);
2
// remember to catch the possible IOException of creating a new FileOutputStream
try
{
3
// the static method will initialize a new Log and set the FileOutputStream global
// so it can be used anywhere in the application
Log.setGlobalOutputStream(new FileOutputStream("machine.log", true));
}
catch(IOException ioException)
{
System.err.println("Unable to create log file.");
}
}