Peter Staab
Peter Staab

Reputation: 552

How can I set the log format in Dancer2?

I am trying to change the logging format to include the line number of the file for a Dancer2 app. The default does not seem to do this. If I add the line

log_format: "[%f--%l] %m"

(which seems correct based on the Dancer2::Core::Role::Logger documentation) nothing changes.

Upvotes: 2

Views: 465

Answers (2)

Peter Staab
Peter Staab

Reputation: 552

Thanks @ThisSuitIsBlackNot. I've also discovered that if there are other engines (like for session), they need to be nested in the same "engines" section. I have a session engine and it appears that it needs to be done as

logger: Console
session: YAML

engines:
  logger:
    Console:
      log_level: debug
      log_format: "[%f----%l] %m"
  session:
    YAML:
      session_dir: /tmp/dancer-sessions

I had the session engine information and it appeared that the console engine information was overwritten.

Upvotes: 1

ThisSuitIsBlackNot
ThisSuitIsBlackNot

Reputation: 24063

log_format isn't a global configuration directive. It's specific to the particular logging engine you're using, so you have to put it in the configuration section for that engine.

For example, if you're using the Dancer2::Logger::File engine:

logger: "File"

engines:
  logger:
    File:
      log_format: "[%f--%l] %m"

Upvotes: 2

Related Questions