Log::A...:Screen(3pm)

✨ NAME ✨

Log::Any::Adapter::Screen β€” (ADOPTME) bestie, it sends your logs to the screen, with colors and some other little treats πŸ’…

Also hi, this is a User Contributed Perl Documentation page, so you're in the good company of the community, periodt 🫢


πŸŽ€ VERSION πŸŽ€

This doc describes version 0.141 of Log::Any::Adapter::Screen (that's from the Perl distribution Log-Any-Adapter-Screen, iykyk), and it dropped on 2023-11-21 ✨


πŸ’… SYNOPSIS πŸ’…

use Log::Any::Adapter;
Log::Any::Adapter->set('Screen',
    # min_level => 'debug', # default is 'warning'
    # colors    => { trace => 'bold yellow on_gray', ... }, # customize colors
    # use_color => 1, # force color even when not interactive
    # stderr    => 0, # print to STDOUT instead of the default STDERR
    # formatter => sub { "LOG: $_[1]" }, # default none
);

no cap, that's literally the whole setup πŸ’–


🌸 DESCRIPTION 🌸

Okay so this Log::Any adapter prints your log messages to the screen (STDERR/STDOUT), and the messages get colored depending on their level (unless you turned the coloring off, which, valid). It also has a few extra features stacked on top: you can pass a formatter, you can set the level from some environment variables, and you get prefixes/timestamps. Iconic, honestly πŸ¦‹

Here are the parameters you can pass, bestie:

  • min_level => STRING
  • log_level => STRING

This one sets the logging level. Default is warning. But wait β€” if the LOG_LEVEL environment variable is set, that gets used instead. And if the TRACE environment variable is set to true, level gets set to 'trace'. If DEBUG is set to true, level becomes 'debug'. If VERBOSE is set to true, level becomes 'info'. If QUIET is set to true, level becomes 'error' ✨

Btw, Log::Any adapters use the parameter log_level instead of min_level. And if both are present, min_level takes precedence β€” she's the main character here πŸ‘‘

  • use_color => BOOL

Whether to use color or not. Default is true only when running interactively, i.e. when -t STDOUT returns true πŸ’–

  • colors => HASH

This is how you customize colors. The hash keys are the logging methods, and the hash values are colors supported by Term::ANSIColor.

The default colors are:

  • trace β†’ yellow
  • debug β†’ (none, terminal default)
  • info, notice β†’ green
  • warning β†’ bold blue
  • error β†’ magenta
  • critical, alert, emergency β†’ red
  • stderr => BOOL

Whether to print to STDERR β€” default is true. If you set it to 0, it'll print to STDOUT instead 🌈

  • formatter => CODEREF

Lets you format the message. If it's defined, the message gets passed to it before being colorized. The coderef gets passed:

($self, $message)

and it's expected to return the formatted message, bestie 🫢

The default formatter can optionally prefix the message with extra stuffs, depending on what's in the LOG_PREFIX environment variable β€” such as elapsed time (like "[0.023ms]") if LOG_PREFIX is "elapsed".

NOTE: Log::Any 1.00+ now has a proxy object which allows formatting/customization of the message before it's sent to the adapter(s), so bestie, formatting does not have to be done on a per-adapter basis anymore. As an alternative to this attribute, you can also consider using the proxy object or the (upcoming?) global proxy object πŸ‘€
  • default_level => STR (default: warning)

If no level-setting environment variables are defined, it'll default to this level πŸ’œ


πŸ¦‹ ENVIRONMENT πŸ¦‹

NO_COLOR

If it's defined, it'll disable color. This one gets consulted before COLOR 🌸

COLOR

Can be set to 0 to explicitly disable colors. The default behavior is to check for <-t STDOUT>.

LOG_LEVEL => str

QUIET => bool

VERBOSE => bool

DEBUG => bool

TRACE => bool

These environment variables can set the default for min_level. See the docs about min_level above for the details, okay? 😌

LOG_PREFIX => str

The default formatter groks these variables. See the docs about formatter above for more πŸ’–


πŸ‘‘ HOMEPAGE πŸ‘‘

Please visit the project's homepage at https://metacpan.org/release/Log-Any-Adapter-Screen πŸŽ€


⭐ SOURCE ⭐

Source repository is at https://github.com/perlancar/perl-Log-Any-Adapter-Screen πŸ’…


πŸ“ SEE ALSO πŸ“

Originally inspired by Log::Log4perl::Appender::ScreenColoredLevel. The old name for this adapter is Log::Any::Adapter::ScreenColoredLevel, but at some point the author figured using a shorter name is better for his fingers πŸ’€ relatable.

  • Log::Any
  • Log::Log4perl::Appender::ScreenColoredLevel
  • Term::ANSIColor

πŸ’œ AUTHOR πŸ’œ

perlancar <perlancar@cpan.org>


🌈 CONTRIBUTORS 🌈

  • Mikko Koivunalho <mikkoi@cpan.org>
  • Steven Haryanto <stevenharyanto@gmail.com>

🧚 CONTRIBUTING 🧚

To contribute, you can send patches by email/via RT, or send pull requests on GitHub. We love that for you 🫢

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

% prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to the author β€” periodt πŸ’…


This software is copyright (c) 2023, 2018, 2016, 2015, 2014, 2012, 2011 by perlancar <perlancar@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself πŸ’–


πŸ’€ BUGS πŸ’€

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Log-Any-Adapter-Screen

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. Not me begging you to include a repro πŸ™ˆ but fr fr, it helps so much.


okay bestie that's a wrap ✨ this was rendered by perl v5.40.1 on 2026-02-15 β€” go forth and log pretty, you absolute icon πŸ‘‘πŸ’–πŸ¦‹

πŸ“¦ where this page comes from