php Monolog-Handler-StreamHandler类(方法)实例源码

下面列出了php Monolog-Handler-StreamHandler 类(方法)源码代码实例,从而了解它的用法。

作者:krisanalf    项目:b-com   
/**
  * Initialize the provider
  *
  * @return void
  */
 public function initialize()
 {
     $this->options = array_merge($this->defaultConfig, $this->options);
     date_default_timezone_set($this->options['log.timezone']);
     // Finally, create a formatter
     $formatter = new LineFormatter($this->options['log.outputformat'], $this->options['log.dateformat'], false);
     // Create a new directory
     $logPath = realpath($this->app->config('bono.base.path')) . '/' . $this->options['log.path'];
     if (!is_dir($logPath)) {
         mkdir($logPath, 0755);
     }
     // Create a handler
     $stream = new StreamHandler($logPath . '/' . date($this->options['log.fileformat']) . '.log');
     // Set our formatter
     $stream->setFormatter($formatter);
     // Create LogWriter
     $logger = new LogWriter(array('name' => $this->options['log.name'], 'handlers' => array($stream), 'processors' => array(new WebProcessor())));
     // Bind our logger to Bono Container
     $this->app->container->singleton('log', function ($c) {
         $log = new Log($c['logWriter']);
         $log->setEnabled($c['settings']['log.enabled']);
         $log->setLevel($c['settings']['log.level']);
         $env = $c['environment'];
         $env['slim.log'] = $log;
         return $log;
     });
     // Set the writer
     $this->app->config('log.writer', $logger);
 }

作者:ewak    项目:supermonolog-service-provide   
public function register(Application $app)
 {
     //parent service provider activation
     $app->register(new MonologServiceProvider());
     //define default options
     $app['monolog.fingerscrossed.level'] = Logger::NOTICE;
     $app['monolog.fingerscrossed'] = true;
     $app['monolog.rotatingfile'] = false;
     $app['monolog.rotatingfile.maxfiles'] = 10;
     $app['monolog.fingerscrossed.handler'] = function () use($app) {
         $level = SuperMonologServiceProvider::translateLevel($app['monolog.level']);
         return new StreamHandler($app['monolog.logfile']);
     };
     //main override function
     $app['monolog.handler'] = function () use($app) {
         //setup level
         $Activationlevel = SuperMonologServiceProvider::translateLevel($app['monolog.fingerscrossed.level']);
         $level = SuperMonologServiceProvider::translateLevel($app['monolog.level']);
         //debug mode
         if ($app['debug']) {
             $handler = new StreamHandler($app['monolog.logfile'], $level);
             $handler->setFormatter(new \Ibsciss\Monolog\Formatter\LineFormatter());
             return $handler;
         }
         //if rotatingfile enable : figerscrossedHandler override
         if ($app['monolog.rotatingfile']) {
             $app['monolog.fingerscrossed.handler'] = new RotatingFileHandler($app['monolog.logfile'], $app['monolog.rotatingfile.maxfiles'], $level);
         }
         //apply default strategy
         $handler = $app['monolog.fingerscrossed'] ? new FingersCrossedHandler($app['monolog.fingerscrossed.handler'], $Activationlevel) : $app['monolog.fingerscrossed.handler'];
         $handler->setFormatter(new \Ibsciss\Monolog\Formatter\LineFormatter());
         return $handler;
     };
 }

作者:songsiha    项目:simpl   
/**
  * 写入日志
  * @param $msg
  * @param $name
  * @param int $level
  * @param AbstractHandler $handler
  */
 public static function write($msg, $name, $level = Logger::INFO, AbstractHandler $handler = null)
 {
     $name .= '_' . $level;
     $name = $name . '_' . date('Y-m-d-H', Date::now());
     if (isset(self::$loggers[$name])) {
         $logger = self::$loggers[$name];
         if ($handler != null) {
             $logger->pushHandler($handler);
         }
     } else {
         $logger = new Logger($name);
         if ($handler == null) {
             $path = ConfigManager::get('log');
             $handler = new StreamHandler($path . DIRECTORY_SEPARATOR . $name . '.log', $level);
             $formatter = new LineFormatter(ConfigManager::get('log_formatter'), 'Y-m-d H:i:s');
             $handler->setFormatter($formatter);
         }
         $logger->pushHandler($handler);
         self::$loggers[$name] = $logger;
     }
     if (is_scalar($msg) === false) {
         $msg = json_encode($msg);
     }
     $logger->log($level, $msg);
 }

作者:skv    项目:laraex   
protected function createLogger($name)
 {
     $logger_title = "";
     if ($name == "_default_") {
         $logger_title = property_exists($this, "__log_title") ? $this->__log_title : "";
     }
     if ($name == "_default_") {
         $file = property_exists($this, "__log_file") ? storage_path("logs/" . $this->__log_file) : storage_path("logs/common.log");
     } else {
         if (strpos($name, "!") === 0) {
             $file = storage_path(str_replace("!", "", $name));
         } else {
             $file = storage_path("logs/" . $name . ".log");
         }
     }
     if (strpos($file, '%') !== false) {
         $file = str_replace("%d", date("Ymd"), $file);
     }
     if (!file_exists(dirname($file))) {
         mkdir(dirname($file));
     }
     $this->loggers[$name] = new Logger($logger_title, [], [new WebProcessor()]);
     $this->loggers[$name]->pushHandler($handler = new StreamHandler($file), Logger::INFO);
     $handler->setFormatter(new Formatter\LineFormatter(null, null, true, true));
 }

作者:jnc    项目:iRai   
/**
  * @param $functionname
  */
 public function __construct($resourcename)
 {
     //When the HTTP request didn't set a User Agent, set it to a blank
     if (!isset($_SERVER['HTTP_USER_AGENT'])) {
         $_SERVER['HTTP_USER_AGENT'] = '';
     }
     //Default timezone is Brussels
     date_default_timezone_set('Europe/Brussels');
     //This is the current resource that's handled. E.g., stations, connections, vehicleinfo or liveboard
     $this->resourcename = $resourcename;
     try {
         $this->log = new Logger('irapi');
         //Create a formatter for the logs
         $logFormatter = new LineFormatter("%context%\n", 'Y-m-d\\TH:i:s');
         $streamHandler = new StreamHandler(__DIR__ . '/../storage/irapi.log', Logger::INFO);
         $streamHandler->setFormatter($logFormatter);
         $this->log->pushHandler($streamHandler);
         $requestname = ucfirst(strtolower($resourcename)) . 'Request';
         include_once "requests/{$requestname}.php";
         $this->request = new $requestname();
         $this->dataRoot = new DataRoot($resourcename, $this->VERSION, $this->request->getFormat());
     } catch (Exception $e) {
         $this->buildError($e);
     }
 }

作者:spryke    项目:Applicatio   
/**
  * @return \Monolog\Handler\StreamHandler
  */
 protected function createStreamHandler()
 {
     $streamHandler = new StreamHandler(Config::get(LogConstants::LOG_FILE_PATH), Config::get(LogConstants::LOG_LEVEL, Logger::INFO));
     $formatter = new LogstashFormatter('Spryker');
     $streamHandler->setFormatter($formatter);
     return $streamHandler;
 }

作者:activecolla    项目:jobsqueu   
/**
  * Set up test environment.
  */
 public function setUp()
 {
     parent::setUp();
     $this->link = new \MySQLi('localhost', 'root', '');
     if ($this->link->connect_error) {
         throw new \RuntimeException('Failed to connect to database. MySQL said: ' . $this->link->connect_error);
     }
     if (!$this->link->select_db('activecollab_jobs_queue_test')) {
         throw new \RuntimeException('Failed to select database.');
     }
     $this->connection = new MysqliConnection($this->link);
     $this->queue = new MySqlQueue($this->connection);
     $this->dispatcher = new Dispatcher($this->queue);
     $this->log_file_path = dirname(__DIR__) . '/logs/' . date('Y-m-d') . '.txt';
     if (is_file($this->log_file_path)) {
         unlink($this->log_file_path);
     }
     $this->log = new Logger('cli');
     $handler = new StreamHandler($this->log_file_path, Logger::DEBUG);
     $formatter = new LineFormatter();
     $formatter->includeStacktraces(true);
     $handler->setFormatter($formatter);
     $this->log->pushHandler($handler);
     $this->container = new Container(['dispatcher' => $this->dispatcher, 'log' => $this->log]);
 }

作者:abdono    项目:silex_simple_ap   
public function register(Container $app)
 {
     $app['logger'] = function () use($app) {
         return $app['monolog'];
     };
     if ($bridge = class_exists('Symfony\\Bridge\\Monolog\\Logger')) {
         $app['monolog.handler.debug'] = function () use($app) {
             $level = MonologServiceProvider::translateLevel($app['monolog.level']);
             return new DebugHandler($level);
         };
         if (isset($app['request_stack'])) {
             $app['monolog.not_found_activation_strategy'] = function () use($app) {
                 return new NotFoundActivationStrategy($app['request_stack'], array('^/'), $app['monolog.level']);
             };
         }
     }
     $app['monolog.logger.class'] = $bridge ? 'Symfony\\Bridge\\Monolog\\Logger' : 'Monolog\\Logger';
     $app['monolog'] = function ($app) {
         $log = new $app['monolog.logger.class']($app['monolog.name']);
         $handler = new Handler\GroupHandler($app['monolog.handlers']);
         if (isset($app['monolog.not_found_activation_strategy'])) {
             $handler = new Handler\FingersCrossedHandler($handler, $app['monolog.not_found_activation_strategy']);
         }
         $log->pushHandler($handler);
         if ($app['debug'] && isset($app['monolog.handler.debug'])) {
             $log->pushHandler($app['monolog.handler.debug']);
         }
         return $log;
     };
     $app['monolog.formatter'] = function () {
         return new LineFormatter();
     };
     $app['monolog.handler'] = $defaultHandler = function () use($app) {
         $level = MonologServiceProvider::translateLevel($app['monolog.level']);
         $handler = new Handler\StreamHandler($app['monolog.logfile'], $level, $app['monolog.bubble'], $app['monolog.permission']);
         $handler->setFormatter($app['monolog.formatter']);
         return $handler;
     };
     $app['monolog.handlers'] = function () use($app, $defaultHandler) {
         $handlers = array();
         // enables the default handler if a logfile was set or the monolog.handler service was redefined
         if ($app['monolog.logfile'] || $defaultHandler !== $app->raw('monolog.handler')) {
             $handlers[] = $app['monolog.handler'];
         }
         return $handlers;
     };
     $app['monolog.level'] = function () {
         return Logger::DEBUG;
     };
     $app['monolog.listener'] = function () use($app) {
         return new LogListener($app['logger'], $app['monolog.exception.logger_filter']);
     };
     $app['monolog.name'] = 'app';
     $app['monolog.bubble'] = true;
     $app['monolog.permission'] = null;
     $app['monolog.exception.logger_filter'] = null;
     $app['monolog.logfile'] = null;
     $app['monolog.use_error_handler'] = !$app['debug'];
 }

作者:realshado    项目:satis-control-pane   
/**
  * @return \Monolog\Logger
  */
 protected function getLogger()
 {
     $handler = new StreamHandler(storage_path('logs/api_request.log'), Logger::DEBUG);
     $handler->setFormatter(new LineFormatter(null, null, true, true));
     $logger = new Logger('ApiRequestLog');
     $logger->pushHandler($handler);
     return $logger;
 }

作者:tonialcaid    项目:tomat   
public function getLogger($logger)
 {
     $formatter = new LineFormatter();
     $stream = new StreamHandler($_SERVER['DOCUMENT_ROOT'] . "tomata/app/logs/tomata.log");
     $stream->setFormatter($formatter);
     $logger->pushHandler($stream, Logger::INFO);
     return $logger;
 }

作者:gavincsc    项目:jsonlogge   
/**
  * @param $logFolder
  *
  * @return StreamHandler[]
  */
 protected function getStreamHandlers($logFolder)
 {
     // create Monolog file stream
     $stream = new StreamHandler($logFolder . DIRECTORY_SEPARATOR . $this->getLogfileName());
     $stream->pushProcessor(array($this, 'streamProcessor'));
     $stream->setFormatter(new JSONFormatter());
     return [$stream];
 }

作者:realshado    项目:satis-control-pane   
/**
  * @return \Monolog\Logger
  */
 public function getLogger()
 {
     $handler = new StreamHandler(storage_path('logs/builder_sync.log'), Logger::DEBUG);
     $handler->setFormatter(new LineFormatter(null, null, true, true));
     $logger = new Logger('SyncBuildLog');
     $logger->pushHandler($handler);
     return $logger;
 }

作者:jshaye    项目:hookbo   
private function __construct()
 {
     $fileName = sprintf('logs/hookbot-%s.log', Carbon::now()->format('Ymd'));
     $lineFormatter = new LineFormatter(null, null, true, true);
     $streamHandler = new StreamHandler(storage_path($fileName), MonoLogger::DEBUG);
     $streamHandler->setFormatter($lineFormatter);
     $this->logger = new MonoLogger('HookBot', [$streamHandler]);
 }

作者:acp    项目:cor   
/**
  * @param string $channel
  * @param string $level
  */
 private function createChannel($channel, $level)
 {
     $fileName = $this->appPath->getCacheDir() . 'logs/' . $channel . '.log';
     $logLevelConst = constant(\Monolog\Logger::class . '::' . strtoupper($level));
     $stream = new StreamHandler($fileName, $logLevelConst);
     $stream->setFormatter(new LineFormatter(null, null, true));
     $this->channels[$channel] = new \Monolog\Logger($channel, [$stream]);
 }

作者:JanFoerst    项目:bliv   
public function registerLogging()
 {
     $formatter = new LineFormatter(null, null, true, true);
     $stream = new StreamHandler(logdir() . 'error.log', Logger::ERROR);
     $stream->setFormatter($formatter);
     $this->log = new Logger('default');
     $this->log->pushHandler($stream);
 }

作者:comodoj    项目:composer-events-handle   
/**
  * Create a log
  *
  * @param string        $name      Name of the log
  * @param LineFormatter $formatter Formatting object for log entries
  * @param string        $output    Destination of the log entries (filename or stream)
  *
  * @return MonoLogger   $logger    Reference object to the logger created
  */
 private function createLogger($name, LineFormatter $formatter, $output)
 {
     $stream = new StreamHandler($output, MonoLogger::INFO);
     $stream->setFormatter($formatter);
     $logger = new MonoLogger($name);
     $logger->pushHandler($stream);
     return $logger;
 }

作者:victordige    项目:Vatsimph   
/**
  *
  * Get streamhandler
  * @param string $file
  * @param integer $level
  * @return \Monolog\Handler\StreamHandler
  */
 protected function getHandler($file, $level)
 {
     if (empty(self::$handler)) {
         $handler = new StreamHandler($file, $level);
         $handler->setFormatter($this->getCustomFormatter());
         self::$handler = $handler;
     }
     return self::$handler;
 }

作者:omeruce    项目:micro-sample-projec   
/**
  * @param $name
  * @return Logger
  * @throws \Exception
  */
 public function createLogger($name)
 {
     $logger = new Logger($name);
     $stream = new StreamHandler($this->getFilePath($name), $this->getLogLevel($name));
     $stream->setFormatter(new LineFormatter("[%datetime%] [%level_name%] %message% %context%\n"));
     $logger->pushHandler($stream);
     $this->resetLogger($logger);
     return $logger;
 }

作者:chatbox-in    项目:heroku-ph   
public function register()
 {
     $this->app->extend(LoggerInterface::class, function (Logger $log) {
         $handler = new StreamHandler('php://stdout', env("APP_LOGLEVEL", Logger::WARNING));
         $handler->setFormatter(new LineFormatter("%message%\n", null, true, true));
         $log->pushHandler($handler);
         return $log;
     });
 }

作者:glia    项目:pmacontro   
public function before($param)
 {
     $logger = new Logger('Daemon');
     $file_log = $this->log_file;
     $handler = new StreamHandler($file_log, Logger::INFO);
     $handler->setFormatter(new LineFormatter(null, null, false, true));
     $logger->pushHandler($handler);
     $this->logger = $logger;
 }


问题


面经


文章

微信
公众号

扫码关注公众号