-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing universal logger #16
Open
alexzerntev
wants to merge
19
commits into
main
Choose a base branch
from
introducing-universal-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3b48b03
initial commit
alexzerntev f209536
format and headers
alexzerntev 0f7b89a
fix
alexzerntev a930ac8
wip
alexzerntev 31767db
headers and formatting
alexzerntev b1f49c5
fix
alexzerntev 4275c44
fix
alexzerntev 0e0ea1a
fix
alexzerntev fed6c69
fix
alexzerntev 1fa38a4
fix
alexzerntev f9a291c
refactor
alexzerntev 7511643
space
alexzerntev 61d85f3
complied with comments
alexzerntev 9a4456d
revert
alexzerntev f4db43c
wip
alexzerntev 101bff2
wip
alexzerntev d5e82c7
headers
alexzerntev 73a326b
headers and structure
alexzerntev e9cbc6e
fix
alexzerntev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/com/rawlabs/utils/core/logger/RawLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.utils.core.logger; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class RawLogger { | ||
|
||
public final Logger logger; | ||
|
||
public RawLogger(Class<?> clazz) { | ||
logger = LoggerFactory.getLogger(clazz); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/rawlabs/utils/core/logger/RawLoggerWithTraceId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.utils.core.logger; | ||
|
||
class RawLoggerWithTraceId extends RawLogger implements TraceIdLogging { | ||
|
||
public RawLoggerWithTraceId(Class<?> clazz) { | ||
super(clazz); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/scala/com/rawlabs/utils/core/ContextLogging.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.utils.core | ||
|
||
import org.slf4j.MDC | ||
|
||
trait ContextLogging { | ||
final def setContextValue(key: String, value: String): Unit = MDC.put(key, value) | ||
|
||
final def clearContextValue(key: String): Unit = MDC.remove(key) | ||
|
||
final def withContextValue[T](key: String, value: String)(f: => T): T = { | ||
setContextValue(key, value) | ||
try f | ||
finally clearContextValue(key) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/scala/com/rawlabs/utils/core/logger/RawLogging.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.utils.core.logger | ||
|
||
import com.typesafe.scalalogging.StrictLogging | ||
|
||
trait RawLogging extends StrictLogging {} |
15 changes: 15 additions & 0 deletions
15
src/main/scala/com/rawlabs/utils/core/logger/RawLoggingWithTraceId.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.utils.core.logger | ||
|
||
trait RawLoggingWithTraceId extends TraceIdLogging with RawLogging {} |
29 changes: 29 additions & 0 deletions
29
src/main/scala/com/rawlabs/utils/core/logger/TraceIdLogging.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.utils.core.logger | ||
|
||
import com.rawlabs.utils.core.ContextLogging | ||
|
||
private object TraceIdLogging { | ||
private val TRACE_ID = "traceId" | ||
} | ||
|
||
trait TraceIdLogging extends ContextLogging { | ||
import TraceIdLogging._ | ||
|
||
final def setTraceId(traceId: String): Unit = setContextValue(TRACE_ID, traceId) | ||
|
||
final def clearTraceId(): Unit = clearContextValue(TRACE_ID) | ||
|
||
final def withTraceId[T](traceId: String)(f: => T): T = withContextValue(TRACE_ID, traceId)(f) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one inherits the
TraceIdLogging trait
, it can set the trace ID with the dedicated methods (as the name indicates), but also has access to the innerContextLogging
methods that permit to add any random key to MDC. Just wondering if that could be a problem.