• Stars
    star
    23
  • Rank 1,009,023 (Top 21 %)
  • Language
    Perl
  • License
    Other
  • Created almost 14 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Minimal Logger

NAME

Log::Minimal - Minimal but customizable logger.

SYNOPSIS

use Log::Minimal;

critf("%s","foo"); # 2010-10-20T00:25:17 [CRITICAL] foo at example.pl line 12
warnf("%d %s %s", 1, "foo", $uri);
infof('foo');
debugf("foo"); print if $ENV{LM_DEBUG} is true

# with full stack trace
critff("%s","foo");
# 2010-10-20T00:25:17 [CRITICAL] foo at lib/Example.pm line 10, example.pl line 12
warnff("%d %s %s", 1, "foo", $uri);
infoff('foo');
debugff("foo"); print if $ENV{LM_DEBUG} is true

my $serialize = ddf({ 'key' => 'value' });

# die with formatted message
croakf('foo');
croakff('%s %s', $code, $message);

DESCRIPTION

Log::Minimal is Minimal but customizable log module.

EXPORT FUNCTIONS

  • critf(($message:Str|$format:Str,@list:Array));

      critf("could't connect to example.com");
      critf("Connection timeout timeout:%d, host:%s", 2, "example.com");
    

    Display CRITICAL messages. When two or more arguments are passed to the function, the first argument is treated as a format of printf.

      local $Log::Minimal::AUTODUMP = 1;
      critf({ foo => 'bar' });
      critf("dump is %s", { foo => 'bar' });
    

    If $Log::Minimal::AUTODUMP is true, reference or object message is serialized with Data::Dumper automatically.

  • warnf(($message:Str|$format:Str,@list:Array));

    Display WARN messages.

  • infof(($message:Str|$format:Str,@list:Array));

    Display INFO messages.

  • debugf(($message:Str|$format:Str,@list:Array));

    Display DEBUG messages, if $ENV{LM_DEBUG} is true.

  • critff(($message:Str|$format:Str,@list:Array));

      critff("could't connect to example.com");
      critff("Connection timeout timeout:%d, host:%s", 2, "example.com");
    

    Display CRITICAL messages with stack trace.

  • warnff(($message:Str|$format:Str,@list:Array));

    Display WARN messages with stack trace.

  • infoff(($message:Str|$format:Str,@list:Array));

    Display INFO messages with stack trace.

  • debugff(($message:Str|$format:Str,@list:Array));

    Display DEBUG messages with stack trace, if $ENV{LM_DEBUG} is true.

  • croakf(($message:Str|$format:Str,@list:Array));

    die with formatted $message

      croakf("critical error");
      # 2011-06-10T16:27:26 [ERROR] critical error at sample.pl line 23
    
  • croakff(($message:Str|$format:Str,@list:Array));

    die with formatted $message with stack trace

  • ddf($value:Any)

    Utility method that serializes given value with Data::Dumper;

      my $serialize = ddf($hashref);
    

ENVIRONMENT VALUE

  • $ENV{LM_DEBUG}

    To print debugf and debugff messages, $ENV{LM_DEBUG} must be true.

    You can change variable name from LM_DEBUG to arbitrary string which is specified by "env_debug" in use line. Changed variable name affects only in package locally.

      use Log::Minimal env_debug => 'FOO_DEBUG';
      
    
      $ENV{LM_DEBUG}  = 1;
      $ENV{FOO_DEBUG} = 0;
      debugf("hello"); # no output
      
    
      $ENV{FOO_DEBUG} = 1;
      debugf("world"); # print message
    
  • $ENV{LM_COLOR}

    $ENV{LM_COLOR} is used as default value of $Log::Minimal::COLOR

  • $ENV{LM_DEFAULT_COLOR}

    $ENV{LM_DEFAULT_COLOR} is used as default value of $Log::Minimal::DEFAULT_COLOR

    Format of value is "LEVEL=FG;BG:LEVEL=FG;BG:...". "FG" and "BG" are optional.

    For example:

      export LM_DEFAULT_COLOR='debug=red:info=;cyan:critical=yellow;red'
    

CUSTOMIZE

  • $Log::Minimal::COLOR

    Coloring log messages. Disabled by default.

  • $Log::Minimal::PRINT

    To change the method of outputting the log, set $Log::Minimal::PRINT.

      # with PSGI Application. output log with request uri.
      my $app = sub {
          my $env = shift;
          local $Log::Minimal::PRINT = sub {
              my ( $time, $type, $message, $trace,$raw_message) = @_;
              $env->{psgi.errors}->print(
                  "$time [$env->{SCRIPT_NAME}] [$type] $message at $trace\n");
          };
          run_app(...);
      }
    

    $message includes color sequences, If you want raw message text, use $raw_message. default is

      sub {
        my ( $time, $type, $message, $trace,$raw_message) = @_;
        warn "$time [$type] $message at $trace\n";
      }
    
  • $Log::Minimal::DIE

    To change the format of die message, set $Log::Minimal::DIE.

      local $Log::Minimal::PRINT = sub {
          my ( $time, $type, $message, $trace) = @_;
          die "[$type] $message at $trace\n"; # not need time
      };
    

    default is

      sub {
        my ( $time, $type, $message, $trace) = @_;
        die "$time [$type] $message at $trace\n";
      }
    
  • $Log::Minimal::LOG_LEVEL

    Set level to output log.

      local $Log::Minimal::LOG_LEVEL = "WARN";
      infof("foo"); #print nothing
      warnf("foo");
    

    Support levels are DEBUG,INFO,WARN,CRITICAL and NONE. If NONE is set, no output except croakf and croakff. Default log level is DEBUG.

  • $Log::Minimal::AUTODUMP

    Serialize message with Data::Dumper.

      warnf("%s", {foo => 'bar'}); # HASH(0x100804ed0)
    
      local $Log::Minimal::AUTODUMP = 1;
      warnf("dump is %s", {foo=>'bar'}); #dump is {foo=>'bar'}
    
      my $uri = URI->new("http://search.cpan.org/");
      warnf("uri: '%s'", $uri); # uri: 'http://search.cpan.org/'
    

    If message is object and has overload methods like '""' or '0+', Log::Minimal uses it instead of Data::Dumper.

  • $Log::Minimal::TRACE_LEVEL

    Like a $Carp::CarpLevel, this variable determines how many additional call frames are to be skipped. Defaults to 0.

  • $Log::Minimal::ESCAPE_WHITESPACE

    If this value is true, whitespace other than space will be represented as [\n\t\r]. Defaults to 0.

AUTHOR

Masahiro Nagano <kazeburo {at} gmail.com>

THANKS TO

Yuji Shimada (xaicron)

Yoshihiro Sugi (sugyan)

SEE ALSO

LICENSE

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

More Repositories

1

rhebok

High Performance Preforked Rack Handler
C
240
star
2

GrowthForecast

Lightning Fast Graphing/Visualization
Perl
233
star
3

cloudforecast

the server metrics gathering
Perl
149
star
4

chocon

chocon is a simple proxy server for persisting connections between upstream servers.
Go
141
star
5

mysetup

my setup scripts repository
Shell
134
star
6

Gazelle

Preforked Plack Handler for performance freaks
Perl
73
star
7

Kurado

monitor metrics
Perl
71
star
8

Monoceros

PSGI/Plack server with event driven connection manager, preforking workers
Perl
55
star
9

HRForecast

Perl
49
star
10

Proclet

minimalistic Supervisor
Perl
37
star
11

wsgate-server

a websocket to tcp proxy/bridge server
Go
36
star
12

Kossy

sinatra-ish simple waf
Perl
34
star
13

Plack-Middleware-ServerStatus-Lite

Plack-Middleware-ServerStatus-Lite
Perl
25
star
14

prefork_engine

a simple prefork server framework / ruby port of perl's Parallel::Prefork
Ruby
24
star
15

GreenBuckets

Perl
23
star
16

query-digester

pt-query-digest wrapper to make ops simple
Perl
23
star
17

pico_http_parser

Fast HTTP Parser using picohttpparser
Ruby
19
star
18

isucon2_hack

isucon2 hack
Perl
19
star
19

Redis-Jet

Yet another XS implemented Redis client
XS
18
star
20

custom-mackerel-plugins

my custom mackerel plugins
Perl
17
star
21

motarei

Simple tcp proxy for Docker Hot deploy
Go
17
star
22

go-jmx-get

tiny jmx client
Go
16
star
23

DBIx-Sunny

Perl
16
star
24

docker-h2o

Dockerfile for h2o HTTP Server with graceful restart support
Shell
12
star
25

Plack-Builder-Conditionals

Plack::Builder extension
Perl
11
star
26

Plack-Middleware-Expires

mod_expires for plack
Perl
11
star
27

wsgate-client

a websocket to tcp proxy/bridge client server
Go
10
star
28

Plack-Server-AnyEvent-Prefork

Prefork AnyEvent based HTTP Server
Perl
10
star
29

mackerel-plugin-axslog

Yet Another mackerel-plugin for analyzing and visualizing Acesslog
Go
10
star
30

mackerel-plugin-pinging

ICMP Ping RTT custom mackerel plugin
Go
9
star
31

Apache-LogFormat-Compiler

Compile LogFormat to perl-code
Perl
9
star
32

Cache-Memcached-IronPlate

Best practices for Cache::Memcached
Perl
9
star
33

Twiggy-Prefork

Preforking AnyEvent HTTP server for PSGI
Perl
9
star
34

myps

Like pgrep and pkill, grep MySQL processlist and kill threads.
Go
8
star
35

percentile

Go
8
star
36

sabo

bandwidth limiting pipe with collaborative capability
Go
8
star
37

Scope-Container

Perl
8
star
38

build_mysql_mroonga_rpm

build mysql_mroonga.rpm by Vagrant provisioners
Shell
8
star
39

JavaScript-Value-Escape

Perl
7
star
40

isucon3qualifier-myhack

Perl
7
star
41

ppdp

Proxy Protocol Dump Proxy
Go
7
star
42

Scope-Container-DBI

DB connection manager with Scope::Container
Perl
6
star
43

heroku-buildpack-perl-procfile

a Heroku buildpack that runs any perl applications from Procfile
6
star
44

Cookie-Baker

Cookie string generator
Perl
6
star
45

p5-Alien-RRDtool

Installation of RRDs.pm (Perl binding for RRDtool)
Perl
6
star
46

rpm

my rpm repository
6
star
47

NoNoPaste

yet another nopaste
Perl
6
star
48

mackerel-plugin-maxcpu

Go
6
star
49

jstat2gf

Perl
5
star
50

chunkview

chuncked trasnfer visualizer
Perl
5
star
51

Time-TZOffset

Show timezone offset strings like +0900
C
5
star
52

NoNoPaste-Cloud

dotcloud nonopaste
Perl
5
star
53

mysql40dump

mysqldump wrapper for MySQL 4.0
Perl
5
star
54

Plack-Middleware-DBIx-DisconnectAll

Disconnect all database connection at end of request
Perl
5
star
55

isucon5-elimination-public

Perl
5
star
56

POSIX-strftime-Compiler

Perl
5
star
57

HTTP-Entity-Parser

PSGI compliant HTTP Entity Parser
Perl
5
star
58

Plack-Middleware-Scope-Container

Perl
5
star
59

Data-Page-Navigation

adds methods for page navigation link to Data::Page
Perl
4
star
60

docker-perl-build

docker image of perl-build
Shell
4
star
61

Plack-App-PHPCGI

execute PHP script as CGI
Perl
4
star
62

http-dump-request

http-dump-request server and docker container for monitoring and tests
Go
4
star
63

mackerel-plugin-postfix-log

Read and analyze postfix logs
Go
4
star
64

vagrant-destroy-provisioner

vagrant-destroy-provisioner plugin allows a VM to be destroyed as a provisioning step.
Ruby
4
star
65

check_http2

Nagios check_http plugin alternative powered by Go
Go
3
star
66

isucon11-final

final isucasy XI
Vue
3
star
67

diff-detector

a tiny tool
Go
3
star
68

isucon_summer_class_2014

ISUCON ε€ζœŸθ¬›ηΏ’ 2014
Go
3
star
69

CoreListWeb

Module::CoreList Web
Perl
3
star
70

mssh

ssh tool
3
star
71

check-cert-net

Check a remote certification expiry using openssl s_client
Go
3
star
72

mackerel-plugin-log-counter

mackerel metric plugin for count lines in log
Go
3
star
73

Plack-Middleware-Log-Minimal

Perl
3
star
74

mod_copy_header

copy a response header to notes
C
3
star
75

wg-keygen-rep

wireguard keypair generator with salt string
Go
3
star
76

Module-Build-Pluggable-CPANfile

Include cpanfile
Perl
3
star
77

WWW-GoogleAnalytics-Mobile

PSGI Application of Google Analytics for Mobile and client
Perl
3
star
78

Cache-Isolator

Perl
3
star
79

check_memcached_val

nagios plugin for checking value in a memcached server
Perl
3
star
80

check-lastlog

Check users who have not logged in recently
Go
2
star
81

Redis-Tiny

deprecated
Perl
2
star
82

deteco

Simple auth server used JWT & public-key cryptography
Go
2
star
83

isucon5-final-public

Perl
2
star
84

isius

Ping/TCP/HTTP/HTTPS monitoring agent server
Go
2
star
85

mackerel-plugin-resolver-synthetic

mackerel plugin for monitoring dns server as linux resolver
Go
2
star
86

tanzak

γŸγ‚“γ–γ
Perl
2
star
87

go-check-mysql-msr

check multi source replication
Go
2
star
88

connstorm

Go
2
star
89

App-derived

run command periodically and calculate rate and check from network
Perl
2
star
90

Cache-Memcached-Fast-Safe

Cache::Memcached::Fast with sanitizing keys and fork-safe
Perl
2
star
91

DBIx-DSN-Resolver

Resolv hostname within dsn string
Perl
2
star
92

limilic2

Perl
2
star
93

ltsvparser

LTSV (Labeled Tab-separated Values) parser for Go language
Go
2
star
94

private-isu-challenge

Go
2
star
95

Plack-Middleware-AxsLog

Alternative AccessLog Middleware
Perl
2
star
96

the-rp

the reverse HTTP an TCP Reverse proxy supports asynchronous upstream resolution and some balancing strategy
Go
2
star
97

File-RotateLogs

Rotate log file
Perl
2
star
98

relaxlogs

CLI for lestrrat-go/file-rotatelogs
Go
2
star
99

AnyEvent-DNS-Cache-Simple

provides simple cache for AnyEvent::DNS
Perl
2
star
100

Time-Crontab

Parser for crontab date and time field
Perl
2
star