Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
### Log4J wrapper
Repository: https://code.europa.eu/simpl/simpl-open/development/contract-billing/common_logging
1. Import in the project
To import into project add maven dependency:
```
<properties>
<simpl.common.logging.version>1.0.0-SNAPSHOT.39.1a139b97</simpl.common.logging.version>
</properties>
<dependency>
<groupId>eu.simpl</groupId>
<artifactId>SIMPL_COMMON_LOGGING</artifactId>
<version>${simpl.common.logging.version}</version>
</dependency>
and repository
<repositories>
<repository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/897/packages/maven</url>
</repository>
</repositories>
```
2. Normal logging:
LOG.info("message");
```
{
"timestamp": "2024-08-20T06:20:12.201Z",
"level": "INFO",
"message": "Application started",
"thread": "main",
"logger": "eu.simpl.simpl_billing.SimplBillingApplication"
}
```
3. Log Http Message
import static eu.simpl.MessageBuilder.buildMessage;
```
LOG.info(buildMessage(HttpLogMessage.builder()
.msg("HTTP request")
.httpStatus("200")
.httpRequestSize("100")
.httpExecutionTime("100")
.user("user")
.build()));
```
Result:
```
{
"timestamp": "2024-08-19T10:32:54.801Z",
"level": "INFO",
"message":
{
"msg": "HTTP request",
"httpStatus": "200",
"httpRequestSize": "100",
"user": "user",
"httpExecutionTime": "100"
},
"thread": "main",
"logger": "eu.simpl.simpl_billing.SimplBillingApplication"
}
```
4. Custom log level BUSINESS
buildMessage method can not be used with slf4, normal logging yes, can be used with sl4j.
example usage:
```
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import static eu.simpl.MessageBuilder.buildMessage;
private static final Logger LOG = LogManager.getLogger(ClassToBeChanged.class);
LOG.log(Level.getLevel("BUSINESS"), buildMessage(LogMessage.builder()
.origin("origin_name")
.destination("destination_name")
.businessOperations(List.of("operation1", "operation2"))
.messageType(MessageType.RESPONSE)
.correlationId("correlation_id")
.httpStatus("200")
.user("user_name")
.msg("Example log message")
.build()));
```
Result:
```
{
"timestamp": "2024-08-12T12:43:18.437+0200",
"level": "BUSINESS",
"message":
{
"msg": "Network",
"messageType": "RESPONSE",
"businessOperations": "[operation1, operation2]",
"origin": "origin_name",
"httpStatus": "200",
"destination": "destination_name",
"correlationId": "correlation_id",
"user": "user_name"
},
"thread": "main",
"logger": "eu.simple.simpl_billing.SimplBillingApplication",
"httpRequestSize": "null",
"httpExecutionTime": "null"
}
```