-
Notifications
You must be signed in to change notification settings - Fork 130
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
Added Logger that takes an implicit parameter (e.g. CorrelationId) #83
Conversation
What's the pattern for two implicits? |
If you want to log multiple values I think it's natural to put them inside one class: case class TracingDetails(messageId: String, causationId: String, correlationId: String) I don't see a very good reason for having more than one implicit in the signature. |
I like you approach for handling this. How about adding a default MDCMap class, that would basically just be a wrapper arround an immutable map, and then a default implementation of the CanLog trait that takes an MDCMap and add them to the MDC context. Something like: final case class MDCMap(map: scala.collection.immutable.HashMap[String, String])
implicit object CanLogMDCMap extends CanLog[MDCMap] {
override def logMessage(originalMsg: String, a: MDCMap): String = {
a.map.foreach(t ⇒ MDC.put(t._1, t._2))
originalMsg
}
override def afterLog(a: MDCMap): Unit = {
a.map.keys.foreach(MDC.remove)
}
} That would provide a default bridge to the java world. The reason that is important, is that a lot of tools are build arround the concept of MDC values. |
@Kreinoee thanks, I could add that class as well or you could create pull request after this one is merged :) @analytically if you like this idea and you would like to merge it, please let me know, so I can update the pull request. And if you don't like it, I think it should be closed |
@pwliwanow yeah I like this idea, please update your PR |
def afterLog(a: A): Unit = () | ||
} | ||
|
||
@SerialVersionUID(957385465L) |
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.
why a SerialVersionUID and why Serializable?
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.
let's remove this
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.
Just SerialVersionUID
or also Serializable
?
Responding to an earlier question, it just mirrors whats in "regular" Logger
+ to allow Spark users to use it
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.
Ah ok makes sense
Hi @pwliwanow. Will you update the pull request, or should I create a new pull request based on this one, with the CanLogMDCMap objct and MDCMap class? |
@Kreinoee sorry, I forgot about this one. I will update the pull request this week |
Super sounds great. And like analytically I am a bit curious about why CanLog should be serializable? |
We ended up not including the CanLogMDCMap and MDCMap classes. Is it something I should create a new pull request for, or do you think its best without them? |
You're welcome to open a new PR. |
I think |
Including request contextual data in the logs (e.g.
CorrelationId
,UserId
, etc.) is a common scenario, however currently there is no good way to do it.With Java common approach is to use MDC, however I think that in Scala it's a bad idea for two reasons:
Here is relevant part of the code that expresses idea in this pull request:
It should also solve #80