Exemplo n.º 1
0
 /**
  * Initialize objects for logging. We have two logs files:
  * - gid-last-request.log: to see logger for the last request
  * - gid-all-requests.log: to see all logger for all request
  *
  * @param \LoggerHierarchy Object to handle objects for logging.
  * @param mixed Either path to the config file or the configuration as
  *     an array.
  * @return void
  */
 public function configure(\LoggerHierarchy $hierarchy, $input = null)
 {
     //Create a logger layout
     $layout = new \LoggerLayoutPattern();
     $layout->setConversionPattern("%d{Y-m-d H:i:s}[%r] %-5level %C.%M[%L] %msg%n");
     $layout->activateOptions();
     // Create an appender which logs to file
     $appLog = new \LoggerAppenderRollingFile('main');
     $appLog->setFile($this->log_path . 'gid-all-requests.log');
     $appLog->setAppend(true);
     $appLog->setMaxFileSize('2MB');
     $appLog->setMaxBackupIndex(5);
     $appLog->setThreshold($this->threshold);
     $appLog->setLayout($layout);
     $appLog->activateOptions();
     //Create an appender which logs Console
     $appConsole = new \LoggerAppenderFile('console');
     $appConsole->setFile($this->log_path . 'gid-last-request.log');
     $appConsole->setAppend(false);
     $appConsole->setThreshold($this->threshold);
     $appConsole->setLayout($layout);
     $appConsole->activateOptions();
     // Add appenders to the root logger
     $root = $hierarchy->getRootLogger();
     $root->addAppender($appLog);
     $root->addAppender($appConsole);
 }
 /**
  * @return LoggerAppenderRollingFile
  */
 private function createRolloverAppender()
 {
     $layout = new LoggerLayoutSimple();
     $appender = new LoggerAppenderRollingFile("mylogger");
     $appender->setFile(PHPUNIT_TEMP_DIR . '/TEST-rolling.txt');
     $appender->setLayout($layout);
     $appender->setMaxFileSize('1KB');
     $appender->setMaxBackupIndex(2);
     $appender->activateOptions();
     return $appender;
 }
 public function testSimpleLogging()
 {
     $layout = new LoggerLayoutSimple();
     $appender = new LoggerAppenderRollingFile("mylogger");
     $appender->setFileName($this->dir . '/TEST-rolling.txt');
     $appender->setLayout($layout);
     $appender->setMaximumFileSize('1KB');
     $appender->setMaxBackupIndex(2);
     $appender->activateOptions();
     $event = new LoggerLoggingEvent('LoggerAppenderFileTest', new Logger('mycategory'), LoggerLevel::getLevelWarn(), "my message123");
     $i = 0;
     $b = true;
     while ($b) {
         if ($i == 1000) {
             $b = false;
         }
         $appender->append($event);
         $i++;
     }
     $event = new LoggerLoggingEvent('LoggerAppenderFileTest', new Logger('mycategory'), LoggerLevel::getLevelWarn(), "my messageXYZ");
     $appender->append($event);
     $appender->close();
     $file = $this->dir . '/TEST-rolling.txt';
     $data = file($file);
     $line = $data[count($data) - 1];
     $e = "WARN - my messageXYZ" . PHP_EOL;
     self::assertEquals($e, $line);
     $file = $this->dir . '/TEST-rolling.txt.1';
     $data = file($file);
     $line = $data[count($data) - 1];
     $e = "WARN - my message123" . PHP_EOL;
     foreach ($data as $r) {
         self::assertEquals($e, $r);
     }
     $file = $this->dir . '/TEST-rolling.txt.2';
     $data = file($file);
     $line = $data[count($data) - 1];
     $e = "WARN - my message123" . PHP_EOL;
     foreach ($data as $r) {
         self::assertEquals($e, $r);
     }
     if (file_exists($this->dir . '/TEST-rolling.txt.3')) {
         self::assertTrue(false);
     }
 }
Exemplo n.º 4
0
 /**
  *  Helper function.
  *
  *  Configures Apache's Log4PHP RootLogger based on values obtained from the
  *  ESAPI properties file.  All instances of Log4PHP Logger will inherit the
  *  configuration.
  *
  *  @return does not return a value.
  */
 private static function _initialise()
 {
     self::$_initialised = true;
     $secConfig = ESAPI::getSecurityConfiguration();
     $logLevel = $secConfig->getLogLevel();
     // Patterns representing the format of Log entries
     // d date, p priority (level), m message, n newline
     $dateFormat = $secConfig->getLogFileDateFormat();
     $logfileLayoutPattern = "%d{{$dateFormat}} %m %n";
     // LogFile properties.
     $logFileName = $secConfig->getLogFileName();
     $maxLogFileSize = $secConfig->getMaxLogFileSize();
     $maxLogFileBackups = $secConfig->getMaxLogFileBackups();
     // LogFile layout
     $logfileLayout = new LoggerLayoutPattern();
     $logfileLayout->setConversionPattern($logfileLayoutPattern);
     // LogFile RollingFile Appender
     $appenderLogfile = new LoggerAppenderRollingFile('ESAPI LogFile');
     $appenderLogfile->setFile($logFileName, true);
     $appenderLogfile->setMaxFileSize($maxLogFileSize);
     $appenderLogfile->setMaxBackupIndex($maxLogFileBackups);
     $appenderLogfile->setLayout($logfileLayout);
     if ($logLevel !== 'OFF') {
         $appenderLogfile->activateOptions();
     }
     // Get the RootLogger and reset it, before adding our Appenders and
     // setting our Loglevel
     $rootLogger = Logger::getRootLogger();
     $rootLogger->removeAllAppenders();
     $rootLogger->addAppender($appenderLogfile);
     $rootLogger->setLevel(self::_convertESAPILeveltoLoggerLevel($logLevel));
 }
Exemplo n.º 5
0
<?php

require_once BASE_PATH . "/lib/log/log4php/Logger.php";
$log = Logger::getRootLogger();
$log->setLevel(LoggerLevel::toLevel(AE_LOG_LEVEL));
$appender = new LoggerAppenderRollingFile("MyAppender");
$appender->setFile(BASE_PATH . "/log/tephlon.log", true);
$appender->setMaxBackupIndex(10);
$appender->setMaxFileSize("10MB");
$appenderlayout = new LoggerLayoutPattern();
$pattern = '%d{d.m.Y H.i.s:u} [%p] %t: %m (at %M)%n';
//$pattern = '%d{d.m.Y H.i.s:u} [%p] %m %n';
$appenderlayout->setConversionPattern($pattern);
$appender->setLayout($appenderlayout);
$appender->activateOptions();
$log->removeAllAppenders();
$log->addAppender($appender);
$log->info(" *** Engine initializing ***");
function getLogger()
{
    global $log;
    return $log;
}
function initLogger()
{
    $loggerName = "log";
    // Iterate over all declared classes
    $classes = get_declared_classes();
    foreach ($classes as $class) {
        $reflection = new ReflectionClass($class);
        // If the class is internally defined by PHP or has no property called "logger", skip it.
 public function testLoggingViaLogger()
 {
     $logger = Logger::getLogger('mycat');
     $logger->setAdditivity(false);
     $layout = new LoggerLayoutSimple();
     $appender = new LoggerAppenderRollingFile("mylogger");
     $appender->setFile($this->dir . '/TEST-rolling.txt');
     $appender->setLayout($layout);
     $appender->setMaxFileSize('1KB');
     $appender->setMaxBackupIndex(2);
     $appender->activateOptions();
     $logger->addAppender($appender);
     for ($i = 0; $i < 1000; $i++) {
         $logger->warn("my message123");
     }
     $logger->warn("my messageXYZ");
     $file = $this->dir . '/TEST-rolling.txt';
     $data = file($file);
     $line = $data[count($data) - 1];
     $e = "WARN - my messageXYZ" . PHP_EOL;
     self::assertEquals($e, $line);
     $file = $this->dir . '/TEST-rolling.txt.1';
     $data = file($file);
     $line = $data[count($data) - 1];
     $e = "WARN - my message123" . PHP_EOL;
     foreach ($data as $r) {
         self::assertEquals($e, $r);
     }
     $file = $this->dir . '/TEST-rolling.txt.2';
     $data = file($file);
     $line = $data[count($data) - 1];
     $e = "WARN - my message123" . PHP_EOL;
     foreach ($data as $r) {
         self::assertEquals($e, $r);
     }
     if (file_exists($this->dir . '/TEST-rolling.txt.3')) {
         self::assertTrue(false);
     }
 }