@@ -5,38 +5,139 @@ This document described how logging is performed across all 3 different processe
5
5
## Architecture
6
6
7
7
All logging relies on log4j2. Writing log entries should occur only in 1 process.
8
- Other processes should send their entries to writing process.
8
+ Other processes should ** must ** send their entries to writing process.
9
9
10
10
Current design:
11
- 1 . Instrumented process sends its logs to the parent process.
12
- 2 . IDEA
13
- 3 . asddddddddddddddddddddddddddddd
11
+ 1 . Instrumented process sends its logs to the parent process.
12
+ 2 . Parent engine process if started from IDEA receives separate instance of log4j2.xml configuration file.
13
+ By default, it always writes to the same place for all generation queries as current design implies that there are no concurrent generation processes.
14
+ 3 . In other cases(` ContestEstimator ` , ` Gradle/Maven ` tasks, ` CLI ` ) it searches for ` log4j2.xml ` in resources from ` .jar ` it started.
14
15
15
- Logs sent via rd
16
+ Logs from instrumented process are sent via corresponding RD model: ` org.utbot.rd.models.LoggerModel ` ,
17
+ which is instantiated in ` org.utbot.instrumentation.rd.InstrumentedProcess.Companion.invoke ` and
18
+ ` org.utbot.instrumentation.process.InstrumentedProcessMainKt.main ` .
16
19
17
- Folder is here
20
+ Log4j2 configuration file path for Engine process is stored at ` org.utbot.intellij.plugin.process.EngineProcess.log4j2ConfigFile ` .
21
+ It is generated from ` utbot-intellij/src/main/resources/log4j2.xml ` .
18
22
19
- ### Rd factories
23
+ You can override which configuration file to use with ` UtSettings.org.utbot.framework.UtSettings.getEngineProcessLogConfigFile `
24
+ property from ` ~/.utbot/settings.properties ` . This file will be used ** as-is** .
20
25
21
- ## Log4j2 commons
26
+ ### Rd logging
22
27
23
- File it takesz
24
- Treelike
25
- LogLevels
26
- Service which is killed before sth really ends
27
- # Appenders
28
- 1 . Console
29
- 2 . FileAppender
30
- 3 . RollingFileAppender
28
+ Rd has its own logging system, based on ` com.jetbrains.rd.util.Logger ` interface. It is convenient to use
29
+ RD logging as default logging system in instrumented process because log4j2 classes in utbot would be confused
30
+ at concrete execution with log4j2 classes in tested project - we will have duplicated versions of log4j2 libs,
31
+ this would break instrumentation and coverage statistics.
31
32
32
- ## Example of log4j2
33
+ To override default RD strategy - use ` com.jetbrains.rd.util.Logger.Companion.set ` method to provide custom
34
+ ` com.jetbrains.rd.util.ILoggerFactory ` . Already created loggers will be automatically reinstantiated to obtain
35
+ new logger from provided factory. You can obtain logger via ` com.jetbrains.rd.util.getLogger ` function.
33
36
34
- Just how to configure everything in mentioned in code and log file
37
+ It is ** highly advised** to override RD logs before first RD use as default system writes to standard
38
+ output and error streams. Check ` EngineProcessMain ` for RD logging example.
35
39
36
- ## Useful info
40
+ For available RD factories see ` org.utbot.rd.loggers ` package - it contains useful implemented factories,
41
+ which log message in the same format as described in ` utbot-intellij/src/main/resources/log4j2.xml ` .
37
42
38
- Performance - about buffered, flush and how it is not logging
43
+ ## Implementation details
39
44
40
- Docker and gradle -
45
+ ### Additivity
41
46
42
- ## Links
47
+ Sometimes same log entry might be written to log multiple times. At log you will see something like:
48
+ ```
49
+ TODO
50
+ ```
51
+
52
+ This is because of loggers * additivity* - their full names defines tree structure, and events from children
53
+ are visible for parents. For example, following ` log4j2.xml ` configuration in IDEA will produce such problem:
54
+ ```
55
+ TODO
56
+ ```
57
+
58
+ The solution is to manually add ``` additivity="false" ``` tag to all loggers.
59
+ See ` utbot-intellij/src/main/resources/log4j2.xml ` for example.
60
+
61
+ More information is available [ here] ( https://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity ) .
62
+
63
+ ### UtBot plugin
64
+
65
+ As plugin does not support multiple generation processes at a time - all engine processes logs to the same file.
66
+
67
+ UtBot plugin creates log directory ` org.utbot.intellij.plugin.process.EngineProcessKt.engineProcessLogDirectory `
68
+ where places log files. Logs are written by ` RollingFileAppender ` in ` utbot-engine-current.log ` file with rolloing over
69
+ after file reaches 20MB size. Previous log files are named ` utbot-engine-%i.log ` . Log file with
70
+ maximal index is the last one rolled. For example, ` utbot-engine-1.log ` is created earlier than ` utbot-engine-10.log ` .
71
+
72
+ ### Useful
73
+ See auxiliary methods to work with logs at ` UtRdLogUtil.kt ` and ` Logging.kt ` .
74
+ If you want to trace how long execution took - use ` org.utbot.common.LoggingKt.bracket `
75
+ method with corresponding log level scope.
76
+
77
+ Log entries from Instrumented process are logged by ` org.utbot.instrumentation.rd.InstrumentedProcessKt.rdLogger ` .
78
+
79
+ ## How to use log4j2 loggers
80
+
81
+ See related document - [ How to use loggers] ( ../HowToUseLoggers.md ) .
82
+
83
+ ## Miscellaneous
84
+
85
+ ### Performance considerations
86
+
87
+ ` Trace ` log level for RD loggers(for ex. if you specify ` Trace ` for all loggers, or as default level for root logger)
88
+ will enable logging all technical send/receive event from protocol,
89
+ causing ~ 50mb additional logs per generation and *** heavily*** polluting log. This might be useful
90
+ when troubleshooting inter-process communication, but in all other cases prefer ` Debug ` level or
91
+ specify ` Trace ` level per logger explicitly.
92
+
93
+
94
+ If your log message requires some string interpolation - you might cause unnecessary work, for example:
95
+
96
+ ``` kotlin
97
+ val someVeryBigDataStructure = VeryBigDataStructure ()
98
+
99
+ logger.debug(" data structure representation - $someVeryBigDataStructure " ) // <---- interpolation
100
+ ```
101
+ In that code even though message uses ` Debug ` level, interpolation will always occur because
102
+ message is passed as a parameter, which are evaluated at call side. Consider using lambdas:
103
+ ``` kotlin
104
+ // message will be created only if debug log level is available
105
+ logger.debug { " data structure representation - $someVeryBigDataStructure " }
106
+ ```
107
+
108
+ Although now logs are sent from one process to another - performance penalties were not noticed.
109
+ Additional performance can be achieved playing with ` bufferedIO ` and ` immediateFlush ` properties in ` log4j2.xml ` .
110
+ For example you can make following changes in ` utbot-intellij ` :
111
+ ``` xml
112
+ <RollingFile ... bufferedIO =" true" immediateFlush =" false" ... >
113
+ ```
114
+
115
+ This will reduce number of IO operations and use log4j2 buffer more efficiently. The cost it that
116
+ when process terminates - log4j2 terminates logging service before buffer is flushed and
117
+ you will lose last portion of logs. This might be undesired behaviour in tests and debugging,
118
+ but probably acceptable in release.
119
+
120
+ ### Docker and Gradle
121
+
122
+ To see logs in Gradle from console, Docker and CI - add following ` build.gradle.kts ` :
123
+ ``` kotlin
124
+ allprojects {
125
+ tasks {
126
+ withType<Test > {
127
+ testLogging.showStandardStreams = true
128
+ testLogging.showStackTraces = true
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ ## Links
135
+
136
+ Log4j2:
137
+ 1 . [ Architecture] ( https://logging.apache.org/log4j/2.x/manual/architecture.html ) - overall log4j2 description.
138
+ 2 . [ Layouts] ( https://logging.apache.org/log4j/2.x/manual/layouts.html ) - how to format log messages.
139
+ UtBot uses ` Pattern layout ` everywhere.
140
+ 3 . [ Appenders] ( https://logging.apache.org/log4j/2.x/manual/appenders.html ) - about different ways to store log entries,
141
+ different storages for log entries and how to configure them. UtBot uses ` Console ` , ` File ` and ` RollingFile ` appenders.
142
+ 4 . [ Configuration] ( https://logging.apache.org/log4j/2.x/manual/configuration.html ) - what you can write in configuration file,
143
+ precise algorithm which file is used and many other useful info. It is ** highly advised** to read ` Additivity ` part.
0 commit comments