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 1 commit
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
15 changes: 9 additions & 6 deletions core/shared/src/main/scala/zio/logging/LogFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package zio.logging

import zio.internal.stacktracer.Tracer
import zio.logging.internal._
import zio.parser.{ Syntax, _ }
import zio.{ Cause, Chunk, Config, FiberId, FiberRefs, LogLevel, LogSpan, Trace, ZLogger }
Expand Down Expand Up @@ -841,9 +842,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 = Tracer.instance.parseOrNull(trace)
justcoon marked this conversation as resolved.
Show resolved Hide resolved
if (parsed != null) {
justcoon marked this conversation as resolved.
Show resolved Hide resolved
builder.appendText(parsed.file)
} else {
builder.appendText("not-available")
}
}

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

val traceLine: LogFormat = LogFormat.make { (builder, trace, _, _, _, _, _, _, _) =>
trace match {
case Trace(_, _, line) => builder.appendNumeric(line)
case _ => ()
val parsed = Tracer.instance.parseOrNull(trace)
if (parsed != null) {
justcoon marked this conversation as resolved.
Show resolved Hide resolved
builder.appendNumeric(parsed.line)
}
}

Expand Down
23 changes: 13 additions & 10 deletions core/shared/src/main/scala/zio/logging/LoggerNameExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package zio.logging

import zio.internal.stacktracer.Tracer
import zio.{ FiberRefs, Trace }

sealed trait LoggerNameExtractor { self =>
Expand Down Expand Up @@ -78,17 +79,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 = Tracer.instance.parseOrNull(trace)
if (parsed != null) {
justcoon marked this conversation as resolved.
Show resolved Hide resolved
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