Skip to content
Snippets Groups Projects
Commit 830c4e55 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Fixes for lib/SimpleSAML/Logger

parent 907592c7
No related branches found
No related tags found
No related merge requests found
......@@ -61,12 +61,16 @@ class Logger
/**
* This constant defines the string we set the track ID to while we are fetching the track ID from the session
* class. This is used to prevent infinite recursion.
*
* @var string
*/
const NO_TRACKID = '_NOTRACKIDYET_';
/**
* This variable holds the track ID we have retrieved from the session class. It can also be NULL, in which case
* we haven't fetched the track ID yet, or self::NO_TRACKID, which means that we are fetching the track ID now.
*
* @var string
*/
private static $trackid = self::NO_TRACKID;
......@@ -114,20 +118,36 @@ class Logger
*/
private static $shuttingDown = false;
/** @var int */
const EMERG = 0;
/** @var int */
const ALERT = 1;
/** @var int */
const CRIT = 2;
/** @var int */
const ERR = 3;
/** @var int */
const WARNING = 4;
/** @var int */
const NOTICE = 5;
/** @var int */
const INFO = 6;
/** @var int */
const DEBUG = 7;
/**
* Log an emergency message.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function emergency($string)
{
......@@ -138,7 +158,8 @@ class Logger
/**
* Log a critical message.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function critical($string)
{
......@@ -149,7 +170,8 @@ class Logger
/**
* Log an alert.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function alert($string)
{
......@@ -160,7 +182,8 @@ class Logger
/**
* Log an error.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function error($string)
{
......@@ -171,7 +194,8 @@ class Logger
/**
* Log a warning.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function warning($string)
{
......@@ -182,7 +206,8 @@ class Logger
/**
* We reserve the notice level for statistics, so do not use this level for other kind of log messages.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function notice($string)
{
......@@ -193,7 +218,8 @@ class Logger
/**
* Info messages are a bit less verbose than debug messages. This is useful to trace a session.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function info($string)
{
......@@ -205,7 +231,8 @@ class Logger
* Debug messages are very verbose, and will contain more information than what is necessary for a production
* system.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function debug($string)
{
......@@ -216,7 +243,8 @@ class Logger
/**
* Statistics.
*
* @var string $string The message to log.
* @param string $string The message to log.
* @return void
*/
public static function stats($string)
{
......@@ -227,7 +255,8 @@ class Logger
/**
* Set the logger to capture logs.
*
* @var boolean $val Whether to capture logs or not. Defaults to TRUE.
* @param boolean $val Whether to capture logs or not. Defaults to TRUE.
* @return void
*/
public static function setCaptureLog($val = true)
{
......@@ -237,6 +266,7 @@ class Logger
/**
* Get the captured log.
* @return array
*/
public static function getCapturedLog()
{
......@@ -247,7 +277,8 @@ class Logger
/**
* Set the track identifier to use in all logs.
*
* @param $trackId string The track identifier to use during this session.
* @param string $trackId The track identifier to use during this session.
* @return void
*/
public static function setTrackId($trackId)
{
......@@ -261,6 +292,7 @@ class Logger
* This method is intended to be registered as a shutdown handler, so that any pending messages that weren't sent
* to the logging handler at that point, can still make it. It is therefore not intended to be called manually.
*
* @return void
*/
public static function flush()
{
......@@ -299,6 +331,7 @@ class Logger
* Every call to this function must be followed by a call to popErrorMask().
*
* @param int $mask The log levels that should be masked.
* @return void
*/
public static function maskErrors($mask)
{
......@@ -317,6 +350,8 @@ class Logger
* Pop an error mask.
*
* This function restores the previous error mask.
*
* @return void
*/
public static function popErrorMask()
{
......@@ -332,6 +367,7 @@ class Logger
* @param int $level The log level corresponding to this message.
* @param string $message The message itself to log.
* @param boolean $stats Whether this is a stats message or a regular one.
* @return void
*/
private static function defer($level, $message, $stats)
{
......@@ -346,6 +382,11 @@ class Logger
}
/**
* @param \SimpleSAML\Logger\LoggingHandlerInterface|null $handler
* @return void
* @throws \Exception
*/
private static function createLoggingHandler($handler = null)
{
// set to false to indicate that it is being initialized
......@@ -390,7 +431,12 @@ class Logger
self::$loggingHandler->setLogFormat(self::$format);
}
/**
* @param int $level
* @param string $string
* @param bool $statsLog
* @return void
*/
private static function log($level, $string, $statsLog = false)
{
if (self::$loggingHandler === false) {
......
......@@ -16,6 +16,8 @@ class ErrorLogLoggingHandler implements LoggingHandlerInterface
{
/**
* This array contains the mappings from syslog log level to names.
*
* @var array
*/
private static $levelNames = [
Logger::EMERG => 'EMERG',
......@@ -51,6 +53,7 @@ class ErrorLogLoggingHandler implements LoggingHandlerInterface
* Set the format desired for the logs.
*
* @param string $format The format used for logs.
* @return void
*/
public function setLogFormat($format)
{
......@@ -63,6 +66,7 @@ class ErrorLogLoggingHandler implements LoggingHandlerInterface
*
* @param int $level The log level.
* @param string $string The formatted message to log.
* @return void
*/
public function log($level, $string)
{
......
......@@ -13,7 +13,6 @@ use SimpleSAML\Logger;
*/
class FileLoggingHandler implements LoggingHandlerInterface
{
/**
* A string with the path to the file where we should log our messages.
*
......@@ -24,6 +23,8 @@ class FileLoggingHandler implements LoggingHandlerInterface
/**
* This array contains the mappings from syslog log levels to names. Copied more or less directly from
* SimpleSAML\Logger\ErrorLogLoggingHandler.
*
* @var array
*/
private static $levelNames = [
Logger::EMERG => 'EMERGENCY',
......@@ -35,12 +36,17 @@ class FileLoggingHandler implements LoggingHandlerInterface
Logger::INFO => 'INFO',
Logger::DEBUG => 'DEBUG',
];
/** @var string|null */
protected $processname = null;
protected $format;
/** @var string */
protected $format = "%b %d %H:%M:%S";
/**
* Build a new logging handler based on files.
* @param \SimpleSAML\Configuration $config
*/
public function __construct(\SimpleSAML\Configuration $config)
{
......@@ -70,6 +76,7 @@ class FileLoggingHandler implements LoggingHandlerInterface
* Set the format desired for the logs.
*
* @param string $format The format used for logs.
* @return void
*/
public function setLogFormat($format)
{
......@@ -82,6 +89,7 @@ class FileLoggingHandler implements LoggingHandlerInterface
*
* @param int $level The log level.
* @param string $string The formatted message to log.
* @return void
*/
public function log($level, $string)
{
......
......@@ -11,7 +11,6 @@ namespace SimpleSAML\Logger;
interface LoggingHandlerInterface
{
/**
* Constructor for log handlers. It must accept receiving a \SimpleSAML\Configuration object.
*
......@@ -25,6 +24,7 @@ interface LoggingHandlerInterface
*
* @param int $level The log level.
* @param string $string The message to log.
* @return void
*/
public function log($level, $string);
......@@ -33,6 +33,7 @@ interface LoggingHandlerInterface
* Set the format desired for the logs.
*
* @param string $format The format used for logs.
* @return void
*/
public function setLogFormat($format);
}
......@@ -10,11 +10,12 @@ namespace SimpleSAML\Logger;
*/
class StandardErrorLoggingHandler extends FileLoggingHandler
{
/**
* StandardError constructor.
*
* It runs the parent constructor and sets the log file to be the standard error descriptor.
*
* @param \SimpleSAML\Configuration $config
*/
public function __construct(\SimpleSAML\Configuration $config)
{
......
......@@ -13,12 +13,16 @@ use SimpleSAML\Utils\System;
*/
class SyslogLoggingHandler implements LoggingHandlerInterface
{
/** @var bool */
private $isWindows = false;
private $format;
/** @var string */
protected $format = "%b %d %H:%M:%S";
/**
* Build a new logging handler based on syslog.
* @param \SimpleSAML\Configuration $config
*/
public function __construct(\SimpleSAML\Configuration $config)
{
......@@ -40,6 +44,7 @@ class SyslogLoggingHandler implements LoggingHandlerInterface
* Set the format desired for the logs.
*
* @param string $format The format used for logs.
* @return void
*/
public function setLogFormat($format)
{
......@@ -52,6 +57,7 @@ class SyslogLoggingHandler implements LoggingHandlerInterface
*
* @param int $level The log level.
* @param string $string The formatted message to log.
* @return void
*/
public function log($level, $string)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment