示例#1
0
 /**
  * 写入日志
  * @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);
 }
 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;
     };
 }
示例#3
0
 /**
  * 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);
 }
示例#4
0
 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));
 }
示例#5
0
文件: APICall.php 项目: jncn/iRail
 /**
  * @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);
     }
 }
 /**
  * @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;
 }
示例#7
0
 /**
  * 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]);
 }
 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'];
 }
 /**
  * @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;
 }
示例#10
0
 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;
 }
示例#11
0
 /**
  * @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];
 }
 /**
  * @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;
 }
示例#13
0
 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]);
 }
示例#14
0
文件: Logger.php 项目: acp3/core
 /**
  * @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]);
 }
示例#15
0
 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);
 }
示例#16
0
 /**
  * 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;
 }
示例#17
0
 /**
  *
  * 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;
 }
 /**
  * @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;
 }
 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;
     });
 }
示例#20
0
 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;
 }
 private function setLogHandler()
 {
     $dateFormat = 'Y-m-d H:i:s';
     $output = "[%datetime%] (%level_name%):  %message%\n";
     $formatter = new LineFormatter($output, $dateFormat);
     $stream = new StreamHandler('php://stdout');
     $stream->setFormatter($formatter);
     $this->logger->pushHandler($stream);
 }
示例#22
0
 /**
  * @param string $file
  * @param string $level
  * @return StreamHandler
  */
 private function getStreamHandler($file, $level)
 {
     $dateFormat = "c";
     $output = "%datetime% > %level_name% > %message% %context% %extra%\n";
     $formatter = new LineFormatter($output, $dateFormat);
     $streamHandler = new StreamHandler($file, $level);
     $streamHandler->setFormatter($formatter);
     return $streamHandler;
 }
 /**
  * Constructs a new file logger using given file path 
  * 
  * @param string $filePath Path to which to write log output to 
  * 
  * @access public
  * @return void
  */
 public function __construct($file = 'logs/analytics.log')
 {
     $this->logger = new Logger('route');
     $output = "%datetime% [%level_name%] %context% %message% \n";
     $formatter = new LineFormatter($output);
     $stream = new StreamHandler($file, Logger::INFO);
     $stream->setFormatter($formatter);
     $this->logger->pushHandler($stream);
 }
 /**
  * {@inheritdoc}
  */
 public function register()
 {
     $this->container->registerSingleton(['Psr\\Log\\LoggerInterface', 'logger'], function ($container) {
         $logger = new Logger('mako');
         $handler = new StreamHandler($container->get('app')->getPath() . '/storage/logs/' . date('Y-m-d') . '.mako', Logger::DEBUG);
         $handler->setFormatter(new LineFormatter(null, null, true, true));
         $logger->pushHandler($handler);
         return $logger;
     });
 }
示例#25
0
 public function __construct($channel, $appId, $serverId, $path, $level = Logger::INFO)
 {
     // construct the monolog
     $monolog = new Logger($channel);
     $handler = new StreamHandler($path, $level);
     $formatter = new LogstashFormatter($appId, $serverId);
     $handler->setFormatter($formatter);
     $monolog->pushHandler($handler);
     $this->monolog = $monolog;
 }
示例#26
0
 protected function getLogger(Certificate $certificate)
 {
     $logPath = $certificate->getPath() . '/last.log';
     @unlink($logPath);
     $logger = new Logger('issue-new');
     $handler = new StreamHandler($logPath);
     $handler->setFormatter(new LineFormatter("[%datetime%] %level_name%: %message%\n"));
     $logger->pushHandler($handler);
     return $logger;
 }
示例#27
0
文件: Api.php 项目: alzo02/go-get-ssl
 /**
  * @return $this
  */
 public function enableLog()
 {
     $name = $this->mode == 'live' ? "API_PROD" : "API_DEV";
     $this->log = new Logger($name);
     $handler = new StreamHandler($this->getLogPath(), Logger::INFO);
     $handler->setFormatter(new LineFormatter(null, null, true, true));
     $this->log->pushHandler($handler);
     $this->log->info("Log init");
     return $this;
 }
 /**
  * Creates a Log with a single entry
  *
  * @param  string $filename The log file
  * @param  array  $entries  The log entries
  */
 private function createLog($filename, array $entries = [])
 {
     $stream = new StreamHandler($filename, Logger::INFO);
     $stream->setFormatter(new LineFormatter("%message%\n", null));
     $logger = new Logger('segment-io');
     $logger->pushHandler($stream);
     foreach ($entries as $entry) {
         $logger->addInfo(json_encode($entry));
     }
 }
 public function register()
 {
     $this->app->extend(LoggerInterface::class, function (Logger $log) {
         $handler = new StreamHandler('php://stdout', Logger::WARNING);
         $handler->setFormatter(new LineFormatter("%message%\n", null, true, true));
         $log->setHandlers([$handler]);
         return $log;
     });
     $this->commands([Sendmail::class, DBConfig::class]);
 }
示例#30
0
 /**
  * WPLogger constructor.
  * インスタンスの初期化
  */
 private function __construct()
 {
     static::$path = get_template_directory() . '/logs/debug.log';
     static::$logger = new Logger('wptheme');
     $output = "[%datetime%] %level_name%: %message% %context% %extra%\n";
     $formatter = new LineFormatter($output);
     $stream = new StreamHandler(static::$path, Logger::DEBUG);
     $stream->setFormatter($formatter);
     static::$logger->pushHandler($stream);
 }