Skip to content

Commit

Permalink
Added logger service
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Jan 21, 2016
1 parent 7d89199 commit 8ee1de3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/config/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Phalcon\Config;
use Phalcon\Logger;

return new Config([
'database' => [
Expand Down Expand Up @@ -36,5 +37,12 @@
'amazon' => [
'AWSAccessKeyId' => '',
'AWSSecretKey' => ''
],
'logger' => [
'path' => APP_DIR . '/logs/',
'format' => '%date% [%type%] %message%',
'date' => 'D j H:i:s',
'logLevel' => Logger::DEBUG,
'filename' => 'application.log',
]
]);
20 changes: 19 additions & 1 deletion app/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
use Phalcon\Mvc\Model\Metadata\Files as MetaDataAdapter;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Flash\Direct as Flash;

use Phalcon\Logger\Adapter\File as FileLogger;
use Phalcon\Logger\Formatter\Line as FormatterLine;
use Vokuro\Auth\Auth;
use Vokuro\Acl\Acl;
use Vokuro\Mail\Mail;
Expand Down Expand Up @@ -146,3 +147,20 @@
$di->set('acl', function () {
return new Acl();
});

/**
* Logger service
*/
$di->set('logger', function ($filename = null, $format = null) use ($config) {
$format = $format ?: $config->get('logger')->format;
$filename = trim($filename ?: $config->get('logger')->filename, '\\/');
$path = rtrim($config->get('logger')->path, '\\/') . DIRECTORY_SEPARATOR;

$formatter = new FormatterLine($format, $config->get('logger')->date);
$logger = new FileLogger($path . $filename);

$logger->setFormatter($formatter);
$logger->setLogLevel($config->get('logger')->logLevel);

return $logger;
});

0 comments on commit 8ee1de3

Please sign in to comment.