]> gerrit.simantics Code Review - simantics/platform.git/blob - docs/Developer/Utilities/Logging.md
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / docs / Developer / Utilities / Logging.md
1 For uniform logging in Simantics Platform [ The Simple Logging Facade for Java](http://www.slf4j.org/) (`org.slf4j.api`) and [Logback Project](http://logback.qos.ch/) (`ch.qos.logback.classic`) is included in Simantics SDK. To use the SLF4J logging API just include the following bundle in your own plugin's `MANIFEST.MF` dependencies:\r
2 \r
3     Require-Bundle: ..,\r
4     org.slf4j.api\r
5 \r
6 An example usage of logging inside your own java code is presented below:\r
7 \r
8 ~~~\r
9  1: import org.slf4j.Logger;\r
10  2: import org.slf4j.LoggerFactory;\r
11  3:\r
12  4: public class Wombat {\r
13  5:  \r
14  6:   private static final Logger LOGGER = LoggerFactory.getLogger(Wombat.class);\r
15  7:   private Integer t;\r
16  8:   private Integer oldT;\r
17  9:\r
18 10:   public void setTemperature(Integer temperature) {\r
19 11:    \r
20 12:     oldT = t;        \r
21 13:     t = temperature;\r
22 14:\r
23 15:     LOGGER.debug("Temperature set to {}. Old temperature was {}.", t, oldT);\r
24 16:\r
25 17:     if(temperature.intValue() > 50) {\r
26 18:       LOGGER.info("Temperature has risen above 50 degrees.");\r
27 19:     }\r
28 20:   }\r
29 21: }\r
30 ~~~\r
31 \r
32 The SLF4J Manual can be found here: http://www.slf4j.org/manual.html\r
33 \r
34 ## Configuring Logback\r
35 \r
36 By default bundle `org.simantics.logback.configuration` contains the `logback.xml` configuration file in which the logging format and different appenders are defined. By default it looks like this:\r
37 \r
38 ~~~\r
39 <?xml version="1.0" encoding="UTF-8"?>\r
40 <configuration>\r
41 \r
42   <appender name="console" class="ch.qos.logback.core.ConsoleAppender">\r
43     <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->\r
44     <encoder>\r
45       <pattern>%-5p [%d] %c: %m%n%rEx</pattern>\r
46     </encoder>\r
47   </appender>\r
48 \r
49   <appender name="async-console" class="ch.qos.logback.classic.AsyncAppender">\r
50     <appender-ref ref="console" />\r
51   </appender>\r
52 \r
53   <root level="debug">\r
54     <appender-ref ref="async-console" />\r
55   </root>\r
56 </configuration>\r
57 ~~~\r
58 \r
59 This configuration creates a single ''asynchronous'' `ConsoleAppender` which prints all the logging to `System.out` by. An example output would look like:\r
60 \r
61     INFO  [2016-09-23 15:56:25,498] org.simantics.workbench.internal.SimanticsWorkbenchAdvisor: startPlatform finished\r
62 \r
63 It is possible to override this default configuration be giving a VM-argument for the application in format:\r
64 \r
65     -Dlogback.configurationFile="C:\logbacs\logback.xml"\r
66 \r
67 For detailed information see [Logback manual](http://logback.qos.ch/manual/).\r