Permalink
Browse files

Merge branch 'dev/feature-log-handler'

  • Loading branch information...
clicktx committed Mar 21, 2016
2 parents 6631421 + 5e0a4e7 commit aef903bb123094f9fd3a67a4be5f5a8d7cfd451d
Showing with 72 additions and 1 deletion.
  1. +3 −0 .gitignore
  2. +36 −0 config/base.pl
  3. +2 −0 config/development.pl
  4. +2 −0 config/production.pl
  5. +2 −0 config/test.pl
  6. +1 −0 cpanfile
  7. +26 −1 lib/Markets.pm
  8. 0 var/.gitkeep
  9. 0 var/log/.gitkeep
View
@@ -17,3 +17,6 @@ MYMETA.yml
/local/
/.carton/
run_script/
TODO
/var/log/*
!.gitkeep
View
@@ -0,0 +1,36 @@
use strict;
use File::Basename qw(dirname);
my $basedir =
File::Spec->rel2abs( File::Spec->catdir( dirname(__FILE__), '..' ) );
my $log_dir = File::Spec->catdir( $basedir, 'var', 'log' );
+{
# logging setting
'logger' => {
screen => {
log_to => "STDOUT",
maxlevel => "debug",
minlevel => "emergency",
},
file => {
default => {
mode => "append",
},
debug => {
filename => [ $log_dir, "debug.log" ],
maxlevel => "debug",
minlevel => "emergency",
},
common => {
filename => [ $log_dir, "common.log" ],
maxlevel => "info",
minlevel => "warn",
},
error => {
filename => [ $log_dir, "error.log" ],
maxlevel => "warn",
minlevel => "emergency",
},
},
},
};
View
@@ -2,7 +2,9 @@
use File::Basename qw(dirname);
my $basedir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..'));
my $dbpath = File::Spec->catfile($basedir, 'db', 'development.db');
my $base_config = do File::Spec->catfile(dirname(__FILE__), 'base.pl');
+{
%$base_config,
'DBI' => [
"dbi:SQLite:dbname=$dbpath", '', '',
+{
View
@@ -2,7 +2,9 @@
use File::Basename qw(dirname);
my $basedir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..'));
my $dbpath = File::Spec->catfile($basedir, 'db', 'production.db');
my $base_config = do File::Spec->catfile(dirname(__FILE__), 'base.pl');
+{
%$base_config,
'DBI' => [
"dbi:SQLite:dbname=$dbpath", '', '',
+{
View
@@ -2,7 +2,9 @@
use File::Basename qw(dirname);
my $basedir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..'));
my $dbpath = File::Spec->catfile($basedir, 'db', 'test.db');
my $base_config = do File::Spec->catfile(dirname(__FILE__), 'base.pl');
+{
%$base_config,
'DBI' => [
"dbi:SQLite:dbname=$dbpath", '', '',
+{
View
@@ -23,6 +23,7 @@ requires 'Teng::Schema::Declare';
requires 'Text::Xslate', '2.0009';
requires 'parent';
requires 'perl', '5.010_001';
requires 'Log::Handler', '0.87';
# dependencies module
requires 'Plack::Middleware::ReverseProxy', '0.15';
View
@@ -30,6 +30,32 @@ sub db {
$c->{db};
}
use Log::Handler;
sub log {
my $c = shift;
if ( !exists $c->{'log'} ) {
my $conf = $c->config->{logger};
if ( $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'production' ) {
delete $conf->{screen};
delete $conf->{file}->{'debug'};
}
my $log = Log::Handler->new();
$log->config( config => $conf ) or die $log->errstr;
$SIG{__WARN__} = sub { $log->log( warn => @_ ) };
$SIG{__DIE__} = sub { $log->trace( emergency => @_ ) };
$c->{'log'} = $log;
}
$c->{'log'};
}
sub debug {
shift->log->debug(shift);
}
1;
__END__
@@ -44,4 +70,3 @@ This is a main context class for Markets
=head1 AUTHOR
Markets authors.
View
No changes.
View
No changes.

0 comments on commit aef903b

Please sign in to comment.