File: README.md

package info (click to toggle)
libmoox-log-any-perl 0.004004-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 140 kB
  • ctags: 9
  • sloc: perl: 20; makefile: 13
file content (101 lines) | stat: -rw-r--r-- 3,010 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# NAME

MooX::Log::Any - Role to add Log::Any

# VERSION

version 0.004004

# DESCRIPTION

A logging role building a very lightweight wrapper to [Log::Any](https://metacpan.org/pod/Log::Any) for use with your [Moo](https://metacpan.org/pod/Moo) or [Moose](https://metacpan.org/pod/Moose) classes.
Connecting a Log::Any::Adapter should be performed prior to logging the first log message, otherwise nothing will happen, just like with Log::Any

Using the logger within a class is as simple as consuming a role:

    package MyClass;
    use Moo;
    with 'MooX::Log::Any';
    
    sub dummy {
        my $self = shift;
        $self->log->info("Dummy log entry");
    }

The logger needs to be setup before using the logger, which could happen in the main application:

    package main;
    use Log::Any::Adapter;
    # Send all logs to Log::Log4perl
    Log::Any::Adapter->set('Log4perl')
    
    use MyClass;
    my $myclass = MyClass->new();
    $myclass->log->info("In my class"); # Access the log of the object
    $myclass->dummy;                    # Will log "Dummy log entry"

# SYNOPSIS;

    package MyApp;
    use Moo;
    
    with 'MooX::Log::Any';
    
    sub something {
        my ($self) = @_;
        $self->log->debug("started bar");    ### logs with default class catergory "MyApp"
        $self->log->error("started bar");    ### logs with default class catergory "MyApp"
    }

# ACCESSORS

## log

The `log` attribute holds the [Log::Any::Adapter](https://metacpan.org/pod/Log::Any::Adapter) object that implements all logging methods for the
defined log levels, such as `debug` or `error`. As this method is defined also in other logging
roles/systems like [MooseX::Log::LogDispatch](https://metacpan.org/pod/MooseX::Log::LogDispatch) this can be thought of as a common logging interface.

    package MyApp::View::JSON;

    extends 'MyApp::View';
    with 'MooseX:Log::Log4perl';

    sub bar {
      $self->logger->info("Everything fine so far");    # logs a info message
      $self->logger->debug("Something is fishy here");  # logs a debug message
    }

## logger(\[$category\])

This is an alias for log.

# SEE ALSO

[Log::Any](https://metacpan.org/pod/Log::Any), [Moose](https://metacpan.org/pod/Moose), [Moo](https://metacpan.org/pod/Moo)

## Inspired by

Inspired by the work by Chris Prather `<perigrin@cpan.org>` and Ash
Berlin `<ash@cpan.org>` on [MooseX::LogDispatch](https://metacpan.org/pod/MooseX::LogDispatch) and Roland Lammel `<lammel@cpan.org>`

# BUGS AND LIMITATIONS

Please report any bugs or feature requests through github 
[https://github.com/cazador481/MooX-Log-Any](https://github.com/cazador481/MooX-Log-Any).

# CONTRIBUTORS

In alphabetical order:

Jens Rehsack `rehsack@gmail.com>`

# AUTHOR

Edward Ash &lt;eddie+cpan@ashfamily.net>

# COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Edward Ash.

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