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

Akka Typed: Logger not using class name when logging in Behavior #25677

Closed
herzrasen opened this Issue Sep 24, 2018 · 7 comments

Comments

Projects
5 participants
@herzrasen
Copy link

herzrasen commented Sep 24, 2018

Hi,

when using ctx.log to log inside a Behavior, the Logger is always akka.actor.typed.Behavior and not the Class the Behavior is implemented in, which is quite misleading and does not allow filtering the logs on class level.

@patriknw

This comment has been minimized.

Copy link
Member

patriknw commented Sep 24, 2018

ok, let's see what we can improve here.
However, note that there is not always a class, only a function.

@johanandren

This comment has been minimized.

Copy link
Member

johanandren commented Sep 24, 2018

Since the behavior can change, and be nested, it is not always the same class. It would somehow have to figure out the innermost behavior and take the class from that, I guess.

Note that it should currently use the actor path, so that you should be able filter on that.

@danbim

This comment has been minimized.

Copy link
Contributor

danbim commented Nov 27, 2018

Apart from a default behavior using the class name (when nothing else is configured) I think it would be a great help to be able to manually set a logger name (similar to Behaviors.withMdc), e.g.Behaviors.withLoggerName(name: String). This could be used to both:

  • statically set a name for all actor instances of a given behavior (my.pkg.WorkerActor), or
  • to set different names for different instances (WorkerActor-574, WorkerActor-575, ...)
@patriknw

This comment has been minimized.

Copy link
Member

patriknw commented Nov 27, 2018

Good idea.

@patriknw patriknw added this to Backlog in Akka Typed Nov 27, 2018

@patriknw patriknw moved this from Backlog to Ready for production backlog in Akka Typed Dec 11, 2018

@johanandren johanandren moved this from Ready for production backlog to In Progress in Akka Typed Jan 4, 2019

@johanandren johanandren self-assigned this Jan 4, 2019

@johanandren

This comment has been minimized.

Copy link
Member

johanandren commented Jan 4, 2019

The "name" for different instances should already be covered by the default behavior which is to use the actor path as logger source which will be different for different instances, so I think this is just a question of enabling that getting included in your logging infra and no need for additional API.

I'm looking into the class aspect, leaning towards that we'd need something like what you proposed for the the withLoggerClass but also exploring other more automagic ideas.

@johanandren johanandren moved this from In Progress to Reviewing in Akka Typed Jan 4, 2019

@danbim

This comment has been minimized.

Copy link
Contributor

danbim commented Jan 4, 2019

The "name" for different instances should already be covered by the default behavior which is to use the actor path as logger source which will be different for different instances, so I think this is just a question of enabling that getting included in your logging infra and no need for additional API.

Without being able to double-check ATM the behavior I last observed was that my logging had the class name as logger name (akka.actor.typed.Behavior). According to the Akka docs (https://doc.akka.io/docs/akka/2.5/logging.html) this is to be expected:

The SLF4J logger selected for each log event is chosen based on the Class[] of the log source specified when creating the LoggingAdapter, unless that was given directly as a string in which case that string is used (i.e. LoggerFactory.getLogger(c: Class[]) is used in the first case and LoggerFactory.getLogger(s: String) in the second).

Could you provide some guidance on how to get the "logger source" (I believe you mean LogEvent.logSource here, right?) being used as the logger name? Maybe as part of the Akka (Typed) docs?

@johanandren

This comment has been minimized.

Copy link
Member

johanandren commented Jan 4, 2019

It depends a bit on the logger implementation you use, there's an example for logback in the docs here: https://doc.akka.io/docs/akka/current/logging.html#logging-thread-akka-source-and-actor-system-in-mdc

johanandren added a commit that referenced this issue Feb 11, 2019

Logger class for typed actors #25677
* Walk stack to figure out logger class
* User API for getting a customized logger
* API to set logger class, use in receptionists, auto-good-class for EventSourcedBehavior

@johanandren johanandren added this to the 2.5.21 milestone Feb 11, 2019

Akka Typed automation moved this from Reviewing to Done Feb 11, 2019

@ktoso ktoso removed the 3 - in progress label Feb 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.