本文整理汇总了PHP中Monolog\Handler\RotatingFileHandler::setFilenameFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP RotatingFileHandler::setFilenameFormat方法的具体用法?PHP RotatingFileHandler::setFilenameFormat怎么用?PHP RotatingFileHandler::setFilenameFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Monolog\Handler\RotatingFileHandler
的用法示例。
在下文中一共展示了RotatingFileHandler::setFilenameFormat方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($name = 'PHPUnit', $level = 'debug')
{
/**
* Filter growl notifications and send only
* - test failures ($handerLevel = Logger::NOTICE; see GrowlHandler constructor)
* - summary of test suites (message "Results OK ...", or "Results KO ..."
*/
$filters = array(function ($record, $handlerLevel) {
if ($record['level'] > $handlerLevel) {
return true;
}
return preg_match('/^Results/', $record['message']) === 1;
});
$stream = new RotatingFileHandler(__DIR__ . DIRECTORY_SEPARATOR . 'monologTestListener.log', 0, Logger::toMonologLevel($level));
$stream->setFilenameFormat('{filename}-{date}', 'Ymd');
$handlers = array($stream);
try {
// be notified only for test suites and test failures
$growl = new GrowlHandler(array(), Logger::NOTICE);
$handlers[] = new CallbackFilterHandler($growl, $filters);
} catch (\Exception $e) {
// Growl server is probably not started
echo $e->getMessage(), PHP_EOL, PHP_EOL;
}
parent::__construct($name, $handlers);
}
示例2: register
public function register(Application $app)
{
$app->register(new \Silex\Provider\MonologServiceProvider());
$app['monolog.handler'] = function () use($app) {
$levels = Logger::getLevels();
if ($app['debug']) {
$level = Logger::DEBUG;
} else {
$level = $app['config']['log']['log_level'];
}
$RotateHandler = new RotatingFileHandler($app['monolog.logfile'], $app['config']['log']['max_files'], $level);
$RotateHandler->setFilenameFormat($app['config']['log']['prefix'] . '{date}' . $app['config']['log']['suffix'], $app['config']['log']['format']);
$RotateHandler->setFormatter(new LineFormatter(null, null, true));
$FingerCrossedHandler = new FingersCrossedHandler($RotateHandler, new ErrorLevelActivationStrategy($levels[$app['config']['log']['action_level']]));
return $FingerCrossedHandler;
};
$app['listener.requestdump'] = $app->share(function ($app) {
return new \Eccube\EventListener\RequestDumpListener($app);
});
}
示例3: __construct
/**
* @param string $name The logging channel
* @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc.
* @param callable[] $processors Optional array of processors
*/
public function __construct($name, array $handlers = array(), array $processors = array())
{
parent::__construct($name, $handlers, $processors);
// set handler
$elgg_log_level = _elgg_services()->logger->getLevel();
if ($elgg_log_level == \Elgg\Logger::OFF) {
// always log errors
$elgg_log_level = \Elgg\Logger::ERROR;
}
$handler = new RotatingFileHandler(elgg_get_data_path() . 'elasticsearch/client.log', 0, $elgg_log_level);
// create correct folder structure
$date = date('Y/m/');
$path = elgg_get_data_path() . "elasticsearch/{$date}";
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
$handler->setFilenameFormat('{date}_{filename}', 'Y/m/d');
$this->pushHandler($handler);
// set logging processor
$processor = new IntrospectionProcessor();
$this->pushProcessor($processor);
}
示例4: __construct
/**
* Console logger class constructor
*
* @param string $name The logging channel
* @param string $level The minimum logging level
*/
public function __construct($name = 'YourLogger', $level = Logger::DEBUG)
{
$filterRules = array(function ($record) {
if (!array_key_exists('operation', $record['context'])) {
return false;
}
return 'printFooter' === $record['context']['operation'];
});
$stream = new RotatingFileHandler(__DIR__ . '/phpunit-growlhandler-php' . PHP_VERSION_ID . '.log', 30);
$stream->setFilenameFormat('{filename}-{date}', 'Ymd');
$console = new StreamHandler('php://stdout');
$console->setFormatter(new LineFormatter("%message%\n", null, true));
$filter = new FilterHandler($console);
$handlers = array($filter, $stream);
try {
$options = array('resourceDir' => dirname(__DIR__) . '/vendor/pear-pear.php.net/Net_Growl/data/Net_Growl/data', 'defaultIcon' => '80/growl_phpunit.png');
$growl = new GrowlHandler(array('name' => 'PHPUnit ResultPrinter', 'options' => $options), Logger::NOTICE);
$growl->setFormatter(new LineFormatter("Growl for Monolog\n" . "%message%"));
$handlers[] = new CallbackFilterHandler($growl, $filterRules);
} catch (\Exception $e) {
// Growl server is probably not started
}
parent::__construct($name, $handlers);
}
示例5: dirname
*/
$baseDir = dirname(__DIR__);
$vendorDir = $baseDir . '/vendor';
require_once $vendorDir . '/autoload.php';
use Bartlett\Monolog\Handler\GrowlHandler;
use Bartlett\Monolog\Handler\CallbackFilterHandler;
use Monolog\Logger;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Processor\PsrLogMessageProcessor;
$processors = array(new PsrLogMessageProcessor());
// Create the logger
$logger = new Logger('long_process', array(), $processors);
// Create some handlers
$stream = new RotatingFileHandler(__DIR__ . DIRECTORY_SEPARATOR . 'long_process.log');
$stream->setFilenameFormat('{filename}-{date}', 'Ymd');
$logger->pushHandler($stream);
try {
// Create filter rules
$filters = array(function ($record) {
if (!array_key_exists('count', $record['context'])) {
return false;
}
return $record['context']['count'] > 5;
});
$growl = new CallbackFilterHandler(new GrowlHandler(array(), Logger::INFO), $filters);
$logger->pushHandler($growl);
} catch (\Exception $e) {
// Growl server is probably not started
echo $e->getMessage(), PHP_EOL;
}
示例6: getHandler
/**
* log.ymlの内容に応じたHandlerの設定を行う
*
* @param array $channelValues
* @return FingersCrossedHandler
*/
public function getHandler(array $channelValues)
{
$app = $this->app;
$levels = Logger::getLevels();
// ファイル名などの設定を行い、設定がなければデフォルト値を設定
$logFileName = isset($channelValues['filename']) ? $channelValues['filename'] : $app['config']['log']['filename'];
$delimiter = isset($channelValues['delimiter']) ? $channelValues['delimiter'] : $app['config']['log']['delimiter'];
$dateFormat = isset($channelValues['dateformat']) ? $channelValues['dateformat'] : $app['config']['log']['dateformat'];
$logLevel = isset($channelValues['log_level']) ? $channelValues['log_level'] : $app['config']['log']['log_level'];
$actionLevel = isset($channelValues['action_level']) ? $channelValues['action_level'] : $app['config']['log']['action_level'];
$passthruLevel = isset($channelValues['passthru_level']) ? $channelValues['passthru_level'] : $app['config']['log']['passthru_level'];
$maxFiles = isset($channelValues['max_files']) ? $channelValues['max_files'] : $app['config']['log']['max_files'];
$logDateFormat = isset($channelValues['log_dateformat']) ? $channelValues['log_dateformat'] : $app['config']['log']['log_dateformat'];
$logFormat = isset($channelValues['log_format']) ? $channelValues['log_format'] : $app['config']['log']['log_format'];
if ($app['debug']) {
$level = Logger::DEBUG;
} else {
$level = $logLevel;
}
// RotateHandlerの設定
$filename = $app['config']['root_dir'] . '/app/log/' . $logFileName . '.log';
$RotateHandler = new RotatingFileHandler($filename, $maxFiles, $level);
$RotateHandler->setFilenameFormat($logFileName . $delimiter . '{date}' . $app['config']['log']['suffix'], $dateFormat);
// ログフォーマットの設定(設定ファイルで定義)
$RotateHandler->setFormatter(new LineFormatter($logFormat . PHP_EOL, $logDateFormat, true, true));
// FingerCossedHandlerの設定
$FingerCrossedHandler = new FingersCrossedHandler($RotateHandler, new ErrorLevelActivationStrategy($levels[$actionLevel]), 0, true, true, $levels[$passthruLevel]);
// Processorの内容をログ出力
$webProcessor = new WebProcessor();
$uidProcessor = new UidProcessor(8);
$FingerCrossedHandler->pushProcessor(function ($record) use($app, $uidProcessor, $webProcessor) {
// ログフォーマットに出力する値を独自に設定
$record['level_name'] = sprintf("%-5s", $record['level_name']);
// セッションIDと会員IDを設定
$record['session_id'] = null;
$record['user_id'] = null;
if ($app->isBooted()) {
if (isset($app['session'])) {
$sessionId = $app['session']->getId();
if ($sessionId) {
$record['session_id'] = substr(sha1($sessionId), 0, 8);
}
}
if (isset($app['user'])) {
$user = $app->user();
if ($user instanceof Customer || $user instanceof Member) {
$record['user_id'] = $user->getId();
}
}
}
$record['uid'] = $uidProcessor->getUid();
$record['url'] = $webProcessor->getRequestUri();
$record['ip'] = $webProcessor->getClientIp();
$record['referrer'] = $webProcessor->getReferer();
$record['method'] = $webProcessor->getMethod();
$record['user_agent'] = $webProcessor->getUserAgent();
// クラス名などを一旦保持し、不要な情報は削除
$line = $record['extra']['line'];
$functionName = $record['extra']['function'];
// php5.3だとclass名が取得できないため、ファイル名を元に出力
// $className = $record['extra']['class'];
$className = $record['extra']['file'];
// 不要な情報を削除
unset($record['extra']['file']);
unset($record['extra']['line']);
unset($record['extra']['class']);
unset($record['extra']['function']);
$record['class'] = pathinfo($className, PATHINFO_FILENAME);
$record['function'] = $functionName;
$record['line'] = $line;
return $record;
});
// クラス名等を取得するProcessor、ログ出力時にクラス名/関数名を無視するための設定を行っている
$skipClasses = array('Psr\\Log\\', 'Eccube\\Log\\');
$skipFunctions = array('log_info', 'log_notice', 'log_warning', 'log_error', 'log_critical', 'log_alert', 'log_emergency');
$intro = new IntrospectionProcessor(Logger::DEBUG, $skipClasses, $skipFunctions);
$FingerCrossedHandler->pushProcessor($intro);
return $FingerCrossedHandler;
}
示例7: testDisallowFilenameFormatsWithoutDate
/**
* @dataProvider filenameFormatProvider
*/
public function testDisallowFilenameFormatsWithoutDate($filenameFormat, $valid)
{
$handler = new RotatingFileHandler(__DIR__ . '/Fixtures/foo.rot', 2);
$handler->setFilenameFormat($filenameFormat, RotatingFileHandler::FILE_PER_DAY);
if (!$valid) {
$this->assertErrorWasTriggered(E_USER_DEPRECATED, 'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.');
}
}
示例8: initLogger
public function initLogger()
{
$file = __DIR__ . '/../../app/log/site.log';
$this->register(new \Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => $file));
$levels = Logger::getLevels();
$this['monolog'] = $this->share($this->extend('monolog', function ($monolog, $this) use($levels, $file) {
$RotateHandler = new RotatingFileHandler($file, $this['config']['log']['max_files'], $this['config']['log']['log_level']);
$RotateHandler->setFilenameFormat($this['config']['log']['prefix'] . '{date}' . $this['config']['log']['suffix'], $this['config']['log']['format']);
$FingerCrossedHandler = new FingersCrossedHandler($RotateHandler, new ErrorLevelActivationStrategy($levels[$this['config']['log']['action_level']]));
$monolog->popHandler();
$monolog->pushHandler($FingerCrossedHandler);
return $monolog;
}));
}
示例9: register
public function register(BaseApplication $app)
{
// 管理画面
$app->match('/' . $app['config']['admin_route'] . '/plugin/giftwrapping/config', 'Plugin\\GiftWrapping\\Controller\\ConfigController::index')->bind('plugin_GiftWrapping_config');
$app->match('/plugin/giftwrapping/checkout', 'Plugin\\GiftWrapping\\Controller\\GiftWrappingController::index')->bind('plugin_giftwrapping_index');
// Form
$app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app) {
$types[] = new GiftWrappingConfigType($app);
return $types;
}));
// Form Extension
$app['form.type.extensions'] = $app->share($app->extend('form.type.extensions', function ($extensions) use($app) {
$extensions[] = new ShoppingTypeExtension($app);
return $extensions;
}));
// Repository
$app['eccube.plugin.repository.wrapping'] = $app->share(function () use($app) {
return $app['orm.em']->getRepository('Plugin\\GiftWrapping\\Entity\\Wrapping');
});
// Service
$app['eccube.plugin.service.gift_wrapping'] = $app->share(function () use($app) {
return new \Plugin\GiftWrapping\Service\GiftWrappingService($app);
});
// メッセージ登録
$app['translator'] = $app->share($app->extend('translator', function ($translator, \Silex\Application $app) {
$translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
$file = __DIR__ . '/../Resource/locale/message.' . $app['locale'] . '.yml';
if (file_exists($file)) {
$translator->addResource('yaml', $file, $app['locale']);
}
return $translator;
}));
// load config
$conf = $app['config'];
$app['config'] = $app->share(function () use($conf) {
$confarray = array();
$path_file = __DIR__ . '/../Resource/config/path.yml';
if (file_exists($path_file)) {
$config_yml = Yaml::parse(file_get_contents($path_file));
if (isset($config_yml)) {
$confarray = array_replace_recursive($confarray, $config_yml);
}
}
$constant_file = __DIR__ . '/../Resource/config/constant.yml';
if (file_exists($constant_file)) {
$config_yml = Yaml::parse(file_get_contents($constant_file));
if (isset($config_yml)) {
$confarray = array_replace_recursive($confarray, $config_yml);
}
}
return array_replace_recursive($conf, $confarray);
});
// ログファイル設定
$app['monolog.gift.wrapping'] = $app->share(function ($app) {
$logger = new $app['monolog.logger.class']('gift.wrapping.client');
$file = $app['config']['root_dir'] . '/app/log/giftwrapping.log';
$RotateHandler = new RotatingFileHandler($file, $app['config']['log']['max_files'], Logger::INFO);
$RotateHandler->setFilenameFormat('giftwrapping_{date}', 'Y-m-d');
$logger->pushHandler(new FingersCrossedHandler($RotateHandler, new ErrorLevelActivationStrategy(Logger::INFO)));
return $logger;
});
}
示例10: pushHandlers
/**
* Handles the available handlers and pushes them to the Monolog\Logger instance
*
* @return void
*/
protected function pushHandlers()
{
foreach (Config::get('kernel.logs.handlers') as $handler => $options) {
switch ($handler) {
case 'RotatingFileHandler':
if (!$options['enabled']) {
continue;
}
$level = static::nameToLevel($options['level']);
$chmod = 0 . $options['chmod'];
/*
$class = 'Monolog\\Formatter\\' . $options['formatter'];
$formatter = new $class();
*/
// Is this handler enabled for this environment?
if (array_exists(array_flip($options['environments']), Kernel::env())) {
$rotateHandler = new RotatingFileHandler(path('logs') . $options['filename'] . '.log', $options['max'], $level, $chmod);
$rotateHandler->setFilenameFormat('{filename}-{date}', $options['date_format']);
$this->getLogger()->pushHandler($rotateHandler);
}
break;
case 'BrowserConsoleHandler':
if (!$options['enabled']) {
continue;
}
// Is this handler enabled for this environment?
if (array_exists(array_flip($options['environments']), Kernel::env())) {
$this->getLogger()->pushHandler(new BrowserConsoleHandler());
}
break;
}
}
}