Example #1
0
 public function postMessage($message, $type = "DEBUG")
 {
     if (MD_LOGGER_LEVEL === 'DEBUG') {
         switch ($type) {
             case "DEBUG":
                 Analog::log($message, Analog::DEBUG);
                 break;
             case "ERROR":
                 Analog::log($message, Analog::ERROR);
                 break;
             case "WARNING":
                 Analog::log($message, Analog::WARNING);
                 break;
             case "INFO":
                 Analog::log($message, Analog::INFO);
                 break;
             default:
         }
     } else {
         switch ($type) {
             case "ERROR":
                 Analog::log($message, Analog::ERROR);
                 break;
             case "WARNING":
                 Analog::log($message, Analog::WARNING);
                 break;
             case "INFO":
                 Analog::log($message, Analog::INFO);
                 break;
             default:
         }
     }
 }
Example #2
0
 /**
  * @depends test_format
  */
 function test_handler()
 {
     // Test logging using a closure
     Analog::handler(function ($msg) {
         AnalogTest::$log .= vsprintf(Analog::$format, $msg);
     });
     Analog::log('Testing');
     $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 3, Testing\n", self::$log);
 }
Example #3
0
 /**
  * @depends test_format
  */
 function test_handler()
 {
     // Test logging using a closure
     Analog::handler(function ($msg) {
         AnalogTest::$log .= vsprintf(Analog::$format, $msg);
     });
     Analog::log('Testing');
     $this->assertEquals(sprintf("%s, %s, %d, %s\n", 'localhost', gmdate('Y-m-d H:i:s'), 3, 'Testing'), self::$log);
 }
Example #4
0
 public function __construct($message = null, $code = 0)
 {
     if (!file_exists("./log_files")) {
         mkdir('./log_files');
     }
     $this->log_file = './log_files/Log.txt';
     if (!$message) {
         throw new $this('Unknown ' . get_class($this));
     }
     Analog::handler(Analog\Handler\File::init($this->log_file));
     parent::__construct($message, $code);
     Analog::log($this->__toString(), Analog::ERROR);
     $handleFilesFolder = new HandleFilesFolder();
     $handleFilesFolder->handle();
     if (file_exists("FTP_SEMAMPHORE.smph")) {
         unlink("FTP_SEMAMPHORE.smph");
     }
 }
 public function __construct($message = "Unknown error", $code = 0)
 {
     if (!file_exists(MD_LOG_FILE_DIR)) {
         mkdir(MD_LOG_FILE_DIR);
     }
     $this->log_file = MD_LOG_FILE_DIR . '/Log.txt';
     if (!$message) {
         throw new $this('Unknown ' . get_class($this));
     }
     Analog::handler(Analog\Handler\File::init($this->log_file));
     if (gettype($message) !== "string") {
         $message = "Unknown error";
     }
     parent::__construct($message, 10);
     Analog::log($this->__toString(), Analog::ERROR);
     $handleFilesFolder = new HandleFilesFolder();
     $handleFilesFolder->handle();
     if (file_exists(MD_ROOT . "/FTP_SEMAMPHORE.smph")) {
         unlink(MD_ROOT . "/FTP_SEMAMPHORE.smph");
     }
 }
Example #6
0
 /**
  * Default error message
  *
  * @see \Fiets\Fiets::error()
  * @see \Fiets\Fiets::callErrorHandler()
  * @param string $argument
  * @return void
  * @author Bjorn Post
  */
 protected function defaultError($argument = null)
 {
     $title = get_class($argument);
     $code = $argument->getCode();
     $message = $argument->getMessage();
     $file = $argument->getFile();
     $line = $argument->getLine();
     $trace = $argument->getTraceAsString();
     if (PHP_SAPI === 'cli') {
         $out = "";
         $out .= sprintf(" 🐞  %s\n", $title);
         $out .= sprintf("    %s (%s)\n", $message, $code);
         $out .= sprintf("    File: %s:%s\n\n", $file, $line);
         $out .= str_replace(ROOT, '', $trace);
         echo $out;
         exit(1);
     } else {
         if (Configure::read('mode') === 'development') {
             if (!headers_sent()) {
                 header('HTTP/1.1 500 Internal Server Error');
             }
             $style = "html * { padding:0; margin:0; }\n\t\t\t\t\tbody * { padding:10px 20px; max-width: 800px; }\n\t\t\t\t\tbody * * { padding:0; }\n\t\t\t\t\tbody { font:small sans-serif; }\n\t\t\t\t\tbody>div { border-bottom:1px solid #ddd; }\n\t\t\t\t\th1 { font-weight:normal; }\n\t\t\t\t\th2 { margin-bottom:.8em; }\n\t\t\t\t\th2 span { font-size:80%; color:#666; font-weight:normal; }\n\t\t\t\t\th3 { margin:1em 0 .5em 0; }\n\t\t\t\t\th4 { margin:0 0 .5em 0; font-weight: normal; }\n\t\t\t\t\tcode, pre { font-size: 100%; white-space: pre-wrap; }\n\t\t\t\t\ttable { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; margin-top:1.5em; }\n\t\t\t\t\ttbody td, tbody th { vertical-align:top; padding:2px 3px; }\n\t\t\t\t\ttable th { width: 10em; text-align: left; }\n\n\t\t\t\t\t#summary { background: #ffc; }\n\t\t\t\t\t#summary h2 { font-weight: normal; color: #666; }\n\t\t\t\t\t#traceback { background:#eee; line-height:1.5em; }\n\t\t\t\t\t#summary table { border:none; background:transparent; }\n\t\t\t\t\tpre.exception_value { font-family: sans-serif; color: #666; font-size: 1.5em; margin: 10px 0 10px 0; }";
             $html = '<div id="summary">';
             $html .= sprintf('<h1>%s @ %s</h1>', $title, $_SERVER['REQUEST_URI']);
             $html .= sprintf('<pre class="exception_value">%s (%s)</pre>', $message, $code);
             $html .= '<table class="meta">';
             $html .= sprintf('<tr><th>Request Method:</th><td>%s</td></tr>', $_SERVER['REQUEST_METHOD']);
             $html .= sprintf('<tr><th>Request URI:</th><td>%s</td></tr>', $_SERVER['REQUEST_URI']);
             $html .= sprintf('<tr><th>File:</th><td>%s</td></tr>', $file);
             $html .= sprintf('<tr><th>Line:</th><td>%s</td></tr>', $line);
             $html .= '</table>';
             $html .= '</div>';
             if ($title == 'Pheasant\\Database\\Mysqli\\Exception') {
                 $html .= '<div id="traceback">';
                 $html .= '<h2>Query details</h2>';
                 $html .= @sprintf('<pre>%s</pre>', $argument->getTrace()[0]['args'][0]);
                 $html .= '</div>';
             }
             if ($trace) {
                 $html .= '<div id="traceback">';
                 $html .= '<h2>Traceback</h2>';
                 $html .= sprintf('<pre>%s</pre>', str_replace(ROOT, '', $trace));
                 $html .= '</div>';
             }
             echo sprintf("<html><head><title>%s</title><style>%s</style></head><body>%s</body></html>", $title, $style, $html);
         } else {
             ob_clean();
             ob_start();
             echo $this->render('500.html', compact('html', 'title', 'code', 'message', 'file', 'line', 'trace'));
             echo ob_flush();
             ob_end_clean();
         }
     }
     if ($title !== 'Pheasant\\Database\\Mysqli\\Exception') {
         // write errors to log
         if (PHP_SAPI === 'cli') {
             \Analog::log(sprintf('%s - %s: %s (%s) @ %s:%s', $file, $title, $message, $code, $file, $line), \Analog::ERROR);
         } else {
             \Analog::log(sprintf('%s %s - %s: %s (%s) @ %s:%s', $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $title, $message, $code, $file, $line), \Analog::ERROR);
         }
     } else {
         // write errors to log
         if (PHP_SAPI === 'cli') {
             \Analog::log(sprintf('%s - %s: %s (%s) @ %s:%s (%s)', $file, $title, $message, $code, $file, $line, $argument->getTrace()[0]['args'][0]), \Analog::ERROR);
         } else {
             \Analog::log(sprintf('%s %s - %s: %s (%s) @ %s:%s (%s)', $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $title, $message, $code, $file, $line, $argument->getTrace()[0]['args'][0]), \Analog::ERROR);
         }
     }
 }
Example #7
0
<?php

require '../lib/Analog.php';
$log = '';
Analog::handler(Analog\Handler\LevelBuffer::init(Analog\Handler\Variable::init($log), Analog::CRITICAL));
// none of these will trigger sending the log
Analog::log('Debugging...', Analog::DEBUG);
Analog::log('Minor warning...', Analog::WARNING);
Analog::log('An error...', Analog::ERROR);
echo "Log is still empty:\n" . $log . "\n";
// but this will, and will include all the others in the log
Analog::log('Oh noes!', Analog::URGENT);
echo "Log now has everything:\n" . $log;
Example #8
0
 public function postMessage($message)
 {
     Analog::log($message, Analog::ERROR);
 }
Example #9
0
    }
}
// CSV file upload
if (isset($_FILES['new_file'])) {
    if ($_FILES['new_file']['error'] === UPLOAD_ERR_OK) {
        if ($_FILES['new_file']['tmp_name'] != '') {
            if (is_uploaded_file($_FILES['new_file']['tmp_name'])) {
                $res = $csv->store($_FILES['new_file']);
                if ($res < 0) {
                    $error_detected[] = $csv->getErrorMessage($res);
                }
            }
        }
    } else {
        if ($_FILES['new_file']['error'] !== UPLOAD_ERR_NO_FILE) {
            Analog::log($csv->getPhpErrorMessage($_FILES['new_file']['error']), Analog::WARNING);
            $error_detected[] = $csv->getPhpErrorMessage($_FILES['new_file']['error']);
        } else {
            if (isset($_POST['upload'])) {
                $error_detected[] = _T("No files has been seleted for upload!");
            }
        }
    }
}
if (isset($_POST['import']) && isset($_POST['import_file'])) {
    if (isset($_POST['dryrun'])) {
        $dryrun = true;
    } else {
        $dryrun = false;
    }
    $res = $csv->import($_POST['import_file'], $members_fields, $dryrun);
Example #10
0
<?php

require '../lib/Analog.php';
Analog::handler(Analog\Handler\ChromeLogger::init());
// debug-level message
Analog::debug($_SERVER);
// an info message
Analog::info('An error message');
// a warning message
Analog::warning('Turn back before it\'s too late');
// an error with no file/line #'s
Analog::log('Another error message');
Example #11
0
 function test_aliases()
 {
     self::$log = '';
     Analog::urgent('Testing');
     $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 0, Testing\n", self::$log);
     self::$log = '';
     Analog::alert('Testing');
     $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 1, Testing\n", self::$log);
     self::$log = '';
     Analog::error('Testing');
     $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 3, Testing\n", self::$log);
     self::$log = '';
     Analog::warning('Testing');
     $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 4, Testing\n", self::$log);
     self::$log = '';
     Analog::notice('Testing');
     $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 5, Testing\n", self::$log);
     self::$log = '';
     Analog::info('Testing');
     $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 6, Testing\n", self::$log);
     self::$log = '';
     Analog::debug('Testing');
     $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 7, Testing\n", self::$log);
     self::$log = '';
 }
Example #12
0
<?php

require '../lib/Analog.php';
Analog::handler(Analog\Handler\Null::init());
Analog::log('Hellooooooo');
Example #13
0
<?php

require '../lib/Analog.php';
Analog::handler(Analog\Handler\Stderr::init());
Analog::log('Output to php://stderr');
Example #14
0
<?php

require '../lib/Analog.php';
Analog::log('foo');
Analog::log('bar');
echo file_get_contents(Analog::handler());
unlink(Analog::handler());
Example #15
0
<?php

require '../lib/Analog.php';
Analog::handler(Analog\Handler\Mail::init('*****@*****.**', 'Log message', '*****@*****.**'));
Analog::log('Error message');
Example #16
0
     $start = null;
 }
 $end = $request->params('e');
 if (trim($end) === '') {
     $end = null;
 }
 if ($start === null && $end !== null || $start !== null && $end === null) {
     $start = null;
     $end = null;
     throw new \RuntimeException(_('Sub series cannot be instancied; missing one of start or end param!'));
 }
 $series = null;
 try {
     $series = new Series($conf, implode('/', $path), $app_base_url, $start, $end);
 } catch (\RuntimeException $e) {
     Analog::log(_('Cannot load series: ') . $e->getMessage(), Analog::ERROR);
     $app->pass();
 }
 //check if series has content, throw an error if not
 if ($series->getCount() === 0) {
     throw new \RuntimeException(str_replace('%s', $series->getPath(), _('Series "%s" is empty!')));
 }
 $img = null;
 if ($request->params('img') !== null) {
     //get image from its name
     if ($series->setImage($request->params('img'))) {
         $img = $series->getImage();
     }
 } else {
     if ($request->get('num') !== null) {
         //get image from its position
Example #17
0
<?php

require '../lib/Analog.php';
$errors = "Errors:\n";
$warnings = "Warnings:\n";
$debug = "Debug:\n";
Analog::handler(Analog\Handler\Multi::init(array(Analog::ERROR => Analog\Handler\Variable::init($errors), Analog::WARNING => Analog\Handler\Variable::init($warnings), Analog::DEBUG => Analog\Handler\Variable::init($debug))));
Analog::log('First error');
Analog::log('Emergency!', Analog::URGENT);
Analog::log('A warning...', Analog::WARNING);
Analog::log('Some info', Analog::INFO);
Analog::log('Debugging output', Analog::DEBUG);
echo $errors;
echo "-----\n";
echo $warnings;
echo "-----\n";
echo $debug;
Example #18
0
<?php

// 1. Install the GELF classes from https://github.com/Graylog2/gelf-php
require 'GELFMessage.php';
require 'GELFMessagePublisher.php';
require '../lib/Analog.php';
Analog::handler(Analog\Handler\GELF::init('localhost'));
Analog::log('Error message');
Analog::log(array('Debug info', __FILE__, __LINE__), Analog::DEBUG);
Example #19
0
<?php

require '../lib/Analog.php';
Analog::handler(Analog\Handler\Buffer::init(Analog\Handler\Mail::init('*****@*****.**', 'Log messages', '*****@*****.**')));
// will all be sent as one email instead of three
Analog::log('Message one');
Analog::log('Message two');
Analog::log('Message three');
Example #20
0
<?php

require '../lib/Analog.php';
$log_file = 'log.txt';
Analog::handler(Analog\Handler\File::init($log_file));
Analog::log('foo');
Analog::log('bar');
echo file_get_contents($log_file);
unlink($log_file);
Example #21
0
 /**
  * accessor to Analog (if installed)
  *
  * Note: Log messages are ignored if no Analog is available!
  *
  * @access private
  * @param  string   $message
  * @param  integer  $level
  * @return
  **/
 private static function log($message, $level = 3)
 {
     if ($level != self::$loglevel) {
         return;
     }
     if (count(self::$debugfunc)) {
         $caller = debug_backtrace();
         if (!in_array($caller[1]['function'], self::$debugfunc)) {
             return;
         }
     }
     if (!self::$analog && !self::$analog == -1) {
         if (file_exists(dirname(__FILE__) . '/3rdparty/Analog/wblib.init.inc.php')) {
             include_once dirname(__FILE__) . '/3rdparty/Analog/wblib.init.inc.php';
             wblib_init_3rdparty(dirname(__FILE__) . '/debug/', 'wbList', self::$loglevel);
             self::$analog = true;
         } else {
             self::$analog = -1;
         }
     }
     if (self::$analog) {
         \Analog::log($message, $level);
     }
 }
Example #22
0
<?php

require '../lib/Analog.php';
Analog::handler(Analog\Handler\Mongo::init('localhost:27017', 'testing', 'log'));
Analog::log('Error message');
Analog::log('Debug info', Analog::DEBUG);
$m = new Mongo('localhost:27017');
$cur = $m->testing->log->find();
foreach ($cur as $doc) {
    print_r($doc);
}
$m->testing->log->remove();
Example #23
0
<?php

require '../lib/Analog.php';
Analog::handler(Analog\Handler\Syslog::init('analog', 'user'));
Analog::log('Error message', Analog::WARNING);