Logging » History » Version 6
Sergey Smolov, 07/14/2015 02:14 PM
1 | 1 | Igor Melnichenko | h1. Logging |
---|---|---|---|
2 | |||
3 | Currently, Retrascope logging subsystem is based on the JUL framework (java.util.logging). |
||
4 | |||
5 | h2. Format of entries |
||
6 | |||
7 | "date. level: message" |
||
8 | |||
9 | Date format: "yyyy.MM.dd HH:mm:ss.SSS". This field along with level field are automatically filled in by the log formatter, while the message field is constructed by logging object. |
||
10 | Message format: "header: message". Typically, header is a logging object class or instance name. |
||
11 | |||
12 | h2. Usage |
||
13 | |||
14 | The root logger is configured in the ru.ispras.retrascope.Retrascope class as logger with name ru.ispras.retrascope. All loggers of other Retrascope classes must be created with a name of the format "<class_package>.<class/instance_name>" (ru.ispras.retrascope.engine.efsm.simulator.EfsmSimulator, for example). Because of that all such loggers will use the root logger as parent and send their messages to root handlers, so generally there is no need to configure non-root handlers. |
||
15 | 2 | Igor Melnichenko | Logging must be used in all Engine classes. |
16 | 5 | Igor Melnichenko | Four log levels are used in Retrascope: LogLevel.ERROR (renamed Level.SEVERE), LogLevel.WARNING (equals to Level.WARNING), LogLevel.INFO (equals to Level.INFO), LogLevel.DEBUG (renamed Level.FINE). |
17 | 1 | Igor Melnichenko | |
18 | h3. Examples |
||
19 | |||
20 | The usage examples from the EfsmSimulator and Retrascope classes are presented below. |
||
21 | |||
22 | h4. Logger creation |
||
23 | |||
24 | 6 | Sergey Smolov | <pre><code class="java"> |
25 | 1 | Igor Melnichenko | this.logger = Logger.getLogger(this.getClass().getCanonicalName()); |
26 | 6 | Sergey Smolov | </code></pre> |
27 | 1 | Igor Melnichenko | |
28 | h4. Logging message without throwable object |
||
29 | |||
30 | 6 | Sergey Smolov | <pre><code class="java"> |
31 | 1 | Igor Melnichenko | if (this.logger.isLoggable(Level.INFO)) { |
32 | 4 | Igor Melnichenko | this.logger.log(Level.INFO, this.logEntryHeader |
33 | 1 | Igor Melnichenko | + ": starting to process the events: " + events); |
34 | } |
||
35 | 6 | Sergey Smolov | </code></pre> |
36 | 1 | Igor Melnichenko | |
37 | h4. Logging message with throwable object |
||
38 | |||
39 | 6 | Sergey Smolov | <pre><code class="java"> |
40 | 1 | Igor Melnichenko | catch (IOException | SecurityException e) { |
41 | if (Retrascope.logger.isLoggable(Level.SEVERE)) { |
||
42 | 3 | Igor Melnichenko | Retrascope.logger.log(Level.SEVERE, Retrascope.LOG_ENTRY_HEADER + |
43 | 1 | Igor Melnichenko | ": the exception has been encountered during a logging file handler configuring: ", e); |
44 | } |
||
45 | } |
||
46 | 6 | Sergey Smolov | </code></pre> |