Coder Social home page Coder Social logo

robrwo / mojolicious-plugin-log-any Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grinnz/mojolicious-plugin-log-any

0.0 1.0 0.0 66 KB

Mojolicious::Plugin::Log::Any - Use other loggers in a Mojolicious application

Home Page: https://metacpan.org/pod/Mojolicious::Plugin::Log::Any

License: Other

Perl 100.00%

mojolicious-plugin-log-any's Introduction

NAME

Mojolicious::Plugin::Log::Any - Use other loggers in a Mojolicious application

SYNOPSIS

package MyApp;
use Mojo::Base 'Mojolicious';

sub startup {
  my $self = shift;
  
  # Log::Any (default)
  use Log::Any::Adapter {category => 'MyApp'}, 'Syslog';
  $self->plugin('Log::Any');
  
  # Log::Contextual
  use Log::Contextual::WarnLogger;
  use Log::Contextual -logger => Log::Contextual::WarnLogger->new({env_prefix => 'MYAPP'});
  $self->plugin('Log::Any' => {logger => 'Log::Contextual});
  
  # Log::Dispatch
  use Log::Dispatch;
  my $logger = Log::Dispatch->new(outputs => ['File::Locked',
    min_level => 'warning',
    filename  => '/path/to/file.log',
    mode      => 'append',
    newline   => 1,
    callbacks => sub { my %p = @_; '[' . localtime() . '] ' . $p{message} },
  ]);
  $self->plugin('Log::Any' => {logger => $logger});
  
  # Log::Dispatchouli
  use Log::Dispatchouli;
  my $logger = Log::Dispatchouli->new({ident => 'MyApp', facility => 'daemon', to_file => 1});
  $self->plugin('Log::Any' => {logger => $logger});
  
  # Log::Log4perl
  use Log::Log4perl;
  Log::Log4perl->init($self->home->child('log.conf')->to_string);
  $self->plugin('Log::Any' => {logger => 'Log::Log4perl'});
}

# or in a Mojolicious::Lite app
use Mojolicious::Lite;
use Log::Any::Adapter {category => 'Mojolicious::Lite'}, File => app->home->child('myapp.log'), log_level => 'info';
plugin 'Log::Any';

DESCRIPTION

Mojolicious::Plugin::Log::Any is a Mojolicious plugin that redirects the application logger to pass its log messages to an external logging framework using "attach_logger" in Mojo::Log::Role::AttachLogger. By default, Log::Any is used, but a different framework or object may be specified. For Log::Any or Log::Log4perl, log messages are dispatched with a category of the application class name, which is Mojolicious::Lite for lite applications.

The default behavior of the Mojo::Log object to filter messages by level, keep history, prepend a timestamp, and write log messages to a file or STDERR will be suppressed, by setting the application log level to debug (the lowest level) and removing the default "message" in Mojo::Log handler. It is expected that the logging framework output handler will be configured to handle these details as necessary. If you want to customize how the logging framework is attached, use Mojo::Log::Role::AttachLogger directly.

METHODS

Mojolicious::Plugin::Log::Any inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

$plugin->register(Mojolicious->new);
$plugin->register(Mojolicious->new, {logger => $logger});

Register logger in Mojolicious application. Takes the following options:

logger

Logging framework or object to pass log messages to, of a type recognized by "attach_logger" in Mojo::Log::Role::AttachLogger. Defaults to Log::Any.

category

Passed through to "attach_logger" in Mojo::Log::Role::AttachLogger. Defaults to the application name.

prepend_level

Passed through to "attach_logger" in Mojo::Log::Role::AttachLogger.

BUGS

Report any issues on the public bugtracker.

AUTHOR

Dan Book <[email protected]>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by Dan Book.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

SEE ALSO

Mojo::Log, Mojo::Log::Role::AttachLogger

mojolicious-plugin-log-any's People

Contributors

grinnz avatar robrwo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.