Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

RFC: Log::Painless

by radiantmatrix (Parson)
on Mar 15, 2006 at 16:58 UTC ( [id://536876]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
            #!/bin/perl
            use Log::Painless; # sends warnings, info, and exceptions to m
    +ain.log
    ...
            info "Logging begun";
            warn "Hello, there!"; #behaves like warn, but logs warning as 
    +well.
            die  "Program done."; #behaves like die, but logs exception as
    + well.
    
  2. or download this
            use Log::Painless { file => 'myscript.log', level => 'debug' }
    +;
    
  3. or download this
            use Log::Painless { level => 'debug' };
            
    ...
                debug leave;  # as enter, above, but "Left subroutine"
            }
            test_log();
    
  4. or download this
            info 'Starting to connect to data source: '.$dsn;
    
  5. or download this
            eval {
                    $dbh = DBI->connect('dbi:SQLite2:dbname=test.db','',''
    +) or
    ...
                warn "Falling back to CSV file..."
                # do stuff.
            }
    
  6. or download this
            2006-03-14T13:21:32 4508 E (myscript.pl/11):Can't connect!
            2006-03-14T13:21:32 4508 I Caught exception [Can't connect!] 1
    + evals deep in main
            2006-03-14T13:21:32 4508 W (myscript.pl/16):Falling back to CS
    +V file...
    
  7. or download this
            sub test_sub {
                    trace enter;
                    # .. some stuff
            }
    
  8. or download this
            2006-03-14T13:21:33 4509 T Entered subroutine main::test_sub
    
  9. or download this
            sub test_sub {
                    # .. some stuff
                    trace leave;
            }
    
  10. or download this
            2006-03-14T13:21:35 4509 T Left subroutine main::test_sub
    
  11. or download this
            use Log::Painless { file => 'messages.log' };
    
  12. or download this
            use Log::Painless { level => 'debug' }; # only trace will be s
    +upressed
    
  13. or download this
            use Log::Painless { shortcuts => [ 'caught' ] }; # only import
    + caught()
    
  14. or download this
            Log::Painless->divert('debug' => 'debug.log');
    
  15. or download this
            Log::Painless->duplicate('debug' => *STDERR);
    
  16. or download this
            Log::Painless->divert('debug' => 'debug.log');
            Log::Painless->duplicate('debug' => *STDERR);
    
  17. or download this
            use Log::Painless;
            {
    ...
                  $old_warn->(@_);
               };
            }
    
  18. or download this
            Date-Time PID Type-Char Message
            
    With default format settings, this results in something like:
    
  19. or download this
            2006-03-14T14:22:32 4856 E (testlog.pl/10):the death
    
  20. or download this
            use Log::Painless {
                    lineformat => sub { my $m = shift; $m=~s/^(.*?) \d+/$1
    +/; return $m },
            };
    
  21. or download this
    package Log::Painless;
    
    ...
    
    
    1;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://536876]
Approved by xdg
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found