Skip to content
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

optimisation in relation to Trace parse #924

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading