コード例 #1
0
 function __construct(Project $project)
 {
     parent::__construct($project);
     // Log requests to stderr
     $l = Logging\Log::getLogger('phlite.request');
     $h = new Logging\Handler\StreamHandler();
     $h->setFormatter(new ShortExceptionFormatter('{ip} — [{asctime}] {name} [{status}] — {verb} {path} {message} ({levelname})', '%a %b %d %Y %H:%M:%S', $project));
     $l->setLevel(Logging\Logger::INFO);
     $l->addHandler($h);
 }
コード例 #2
0
ファイル: Log.php プロジェクト: iHunt101/phlite
 /**
  * Do basic configuration for the logging system.
  *
  * This function does nothing if the root logger already has handlers
  * configured. It is a convenience method intended for use by simple scripts
  * to do one-shot configuration of the logging package.
  *
  * The default behaviour is to create a StreamHandler which writes to
  * sys.stderr, set a formatter using the BASIC_FORMAT format string, and
  * add the handler to the root logger.
  *
  * A number of optional keyword arguments may be specified, which can alter
  * the default behaviour.
  *
  * filename  Specifies that a FileHandler be created, using the specified
  *           filename, rather than a StreamHandler.
  * filemode  Specifies the mode to open the file, if filename is specified
  *           (if filemode is unspecified, it defaults to 'a').
  * format    Use the specified format string for the handler.
  * datefmt   Use the specified date/time format.
  * level     Set the root logger level to the specified level.
  * stream    Use the specified stream to initialize the StreamHandler. Note
  *           that this argument is incompatible with 'filename' - if both
  *           are present, 'stream' is ignored.
  *
  * Note that you could specify a resource created using fopen(filename,
  * mode) rather than passing the filename and mode in. However, it should be
  * remembered that StreamHandler does not close its stream (since it may be
  * using php://stdout or php://stderr), whereas FileHandler closes its
  * stream when the handler is closed.
  */
 static function basicConfig($config = array())
 {
     if (count(Log::$root->handlers) == 0) {
         $filename = @$config['filename'];
         if ($filename) {
             $mode = @$config['filemode'] ?: 'a';
             $hdlr = new FileHandler($filename, $mode);
         } else {
             $stream = @$config['stream'];
             $hdlr = new StreamHandler($stream);
         }
         $fs = @$config['format'] ?: Log::$BASIC_FORMAT;
         $dfs = @$config['datefmt'] ?: null;
         $fmt = new Formatter($fs, $dfs);
         $hdlr->setFormatter($fmt);
         Log::$root->addHandler($hdlr);
         $level = @$config['level'];
         if (isset($level)) {
             Log::$root->setLevel($level);
         }
     }
 }