The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Dancer2::Logger::Console::Colored - Dancer2 colored console logger.

VERSION

version 0.004

DESCRIPTION

This is a logging engine that allows you to print colored debug messages on the standard error output. It is based on Dancer2::Logger:Console. Refer to its documentation for how to configure the format of your log message.

log

Writes the log message to the console.

CONFIGURATION

The setting logger should be set to Console::Colored in order to use this logging engine in a Dancer2 application.

In your config.yml (or $environment.yml):

    engines:
      logger:
        Console::Colored:
          colored_origin: "cyan"
          colored_levels:
            core: "bold bright_white"
            debug: "bold bright_blue"
            info: "bold green"
            warning: "bold yellow"
            error: "bold yellow on_red"
          colored_messages:
            core: "bold bright_white"
            debug: "bold bright_blue"
            info: "bold green"
            warning: "bold yellow"
            error: "bold yellow on_red"

Using Regex

You can also provide a configuration key colored_regex, which will allow you to give multiple pairs of regular expression patterns and colors. The logger will then change the colors of anything that matches a pattern according to the configuration.

To enable it, use this (additional) configuration.

          colored_regex:
            - re: "customer number \d+"
              color: "bold red"

It can also be used to highlight full lines. Just provide a pattern that grabs everything.

          colored_regex:
            - re: ".+error.+"
              color: "white on_red"

Note that in YAML and other config formats, the pattern can only be a string. If you enable this from within your application, you also also need to supply a string, not a qr//.

    $logger->colored_regex(
        [
            {
                re    => 'foobar',
                color => 'cyan',
            },
            {
                re    => '\d+',
                color => 'magenta',
            },
        ]
    );

BREAKING CHANGES

If you are running on Dancer2 older than 0.166001_01 you will need to use Dancer2::Logger::Console::Colored version 0.001 because Dancer2 changed the way the logging was handled.

SEE ALSO

Dancer2::Logger::Console, Dancer2::Core::Role::Logger, Term::ANSIColor

AUTHOR

BURNERSK <burnersk@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2014 by BURNERSK <burnersk@cpan.org>.

This is free software, licensed under:

  The MIT (X11) License