Skip to content

Commit

Permalink
optimisation in relation to Trace parse (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon authored Jan 5, 2025
1 parent 2c2d7bb commit 0a8fa19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
14 changes: 8 additions & 6 deletions core/shared/src/main/scala/zio/logging/LogFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,11 @@ object LogFormat {

val enclosingClass: LogFormat =
LogFormat.make { (builder, trace, _, _, _, _, _, _, _) =>
trace match {
case Trace(_, file, _) => builder.appendText(file)
case _ => builder.appendText("not-available")
val parsed = Trace.parseOrNull(trace)
if (parsed ne null) {
builder.appendText(parsed.file)
} else {
builder.appendText("not-available")
}
}

Expand All @@ -868,9 +870,9 @@ object LogFormat {
}

val traceLine: LogFormat = LogFormat.make { (builder, trace, _, _, _, _, _, _, _) =>
trace match {
case Trace(_, _, line) => builder.appendNumeric(line)
case _ => ()
val parsed = Trace.parseOrNull(trace)
if (parsed ne null) {
builder.appendNumeric(parsed.line)
}
}

Expand Down
22 changes: 12 additions & 10 deletions core/shared/src/main/scala/zio/logging/LoggerNameExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,19 @@ object LoggerNameExtractor {
* trace with value ''example.LivePingService.ping(PingService.scala:22)''
* will have ''example.LivePingService'' as logger name
*/
val trace: LoggerNameExtractor = FnExtractor((trace, _, _) =>
trace match {
case Trace(location, _, _) =>
val last = location.lastIndexOf(".")
val name = if (last > 0) {
location.substring(0, last)
} else location
Some(name)
case _ => None
val trace: LoggerNameExtractor = FnExtractor { (trace, _, _) =>
val parsed = Trace.parseOrNull(trace)
if (parsed ne null) {
val location = parsed.location
val last = location.lastIndexOf(".")
val name = if (last > 0) {
location.substring(0, last)
} else location
Some(name)
} else {
None
}
)
}

/**
* Extractor which take logger name from annotation
Expand Down

0 comments on commit 0a8fa19

Please sign in to comment.