ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Slim_Logger Class Reference
+ Collaboration diagram for Slim_Logger:

Public Member Functions

 __construct ($directory, $level=4)
 Constructor.
 setDirectory ($directory)
 Set log directory.
 getDirectory ()
 Get log directory.
 setLevel ($level)
 Set log level.
 getLevel ()
 Get log level.
 debug ($data)
 Log debug data.
 info ($data)
 Log info data.
 warn ($data)
 Log warn data.
 error ($data)
 Log error data.
 fatal ($data)
 Log fatal data.
 getFile ()
 Get absolute path to current daily log file.

Protected Member Functions

 log ($data, $level)
 Log data to file.
 write ($data)
 Persist data to log.

Protected Attributes

 $levels
 $directory

Detailed Description

Definition at line 45 of file Logger.php.

Constructor & Destructor Documentation

Slim_Logger::__construct (   $directory,
  $level = 4 
)

Constructor.

Parameters
string$directoryAbsolute or relative path to log directory
int$levelThe maximum log level reported by this Logger

Definition at line 68 of file Logger.php.

References $directory, setDirectory(), and setLevel().

{
$this->setLevel($level);
}

+ Here is the call graph for this function:

Member Function Documentation

Slim_Logger::debug (   $data)

Log debug data.

Parameters
mixed$data
Returns
void

Definition at line 123 of file Logger.php.

References log().

{
$this->log($data, 4);
}

+ Here is the call graph for this function:

Slim_Logger::error (   $data)

Log error data.

Parameters
mixed$data
Returns
void

Definition at line 150 of file Logger.php.

References log().

{
$this->log($data, 1);
}

+ Here is the call graph for this function:

Slim_Logger::fatal (   $data)

Log fatal data.

Parameters
mixed$data
Returns
void

Definition at line 159 of file Logger.php.

References log().

{
$this->log($data, 0);
}

+ Here is the call graph for this function:

Slim_Logger::getDirectory ( )

Get log directory.

Returns
string|false Absolute path to log directory with trailing slash

Definition at line 91 of file Logger.php.

References $directory.

Referenced by getFile(), and log().

{
}

+ Here is the caller graph for this function:

Slim_Logger::getFile ( )

Get absolute path to current daily log file.

Returns
string

Definition at line 167 of file Logger.php.

References getDirectory().

Referenced by write().

{
return $this->getDirectory() . strftime('%Y-%m-%d') . '.log';
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Logger::getLevel ( )

Get log level.

Returns
int

Definition at line 114 of file Logger.php.

Referenced by log().

{
return $this->level;
}

+ Here is the caller graph for this function:

Slim_Logger::info (   $data)

Log info data.

Parameters
mixed$data
Returns
void

Definition at line 132 of file Logger.php.

References log().

{
$this->log($data, 3);
}

+ Here is the call graph for this function:

Slim_Logger::log (   $data,
  $level 
)
protected

Log data to file.

Parameters
mixed$data
int$level
Returns
void
Exceptions
RuntimeExceptionIf log directory not found or not writable

Definition at line 178 of file Logger.php.

References getDirectory(), getLevel(), and write().

Referenced by debug(), error(), fatal(), info(), and warn().

{
$dir = $this->getDirectory();
if ( $dir == false || !is_dir($dir) ) {
throw new RuntimeException("Log directory '$dir' invalid.");
}
if ( !is_writable($dir) ) {
throw new RuntimeException("Log directory '$dir' not writable.");
}
if ( $level <= $this->getLevel() ) {
$this->write(sprintf("[%s] %s - %s\r\n", $this->levels[$level], date('c'), (string)$data));
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Logger::setDirectory (   $directory)

Set log directory.

Parameters
string$directoryAbsolute or relative path to log directory
Returns
void

Definition at line 78 of file Logger.php.

References $directory.

Referenced by __construct().

{
$realPath = realpath($directory);
if ( $realPath ) {
$this->directory = rtrim($realPath, '/') . '/';
} else {
$this->directory = false;
}
}

+ Here is the caller graph for this function:

Slim_Logger::setLevel (   $level)

Set log level.

Parameters
intThe maximum log level reported by this Logger
Returns
void
Exceptions
InvalidArgumentExceptionIf level specified is not 0, 1, 2, 3, 4

Definition at line 101 of file Logger.php.

Referenced by __construct().

{
$theLevel = (int)$level;
if ( $theLevel >= 0 && $theLevel <= 4 ) {
$this->level = $theLevel;
} else {
throw new InvalidArgumentException('Invalid Log Level. Must be one of: 0, 1, 2, 3, 4.');
}
}

+ Here is the caller graph for this function:

Slim_Logger::warn (   $data)

Log warn data.

Parameters
mixed$data
Returns
void

Definition at line 141 of file Logger.php.

References log().

{
$this->log($data, 2);
}

+ Here is the call graph for this function:

Slim_Logger::write (   $data)
protected

Persist data to log.

Parameters
stringLog message
Returns
void

Definition at line 196 of file Logger.php.

References getFile().

Referenced by log().

{
@file_put_contents($this->getFile(), $data, FILE_APPEND | LOCK_EX);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

Slim_Logger::$directory
protected

Definition at line 61 of file Logger.php.

Referenced by __construct(), getDirectory(), and setDirectory().

Slim_Logger::$levels
protected
Initial value:
array(
0 => 'FATAL',
1 => 'ERROR',
2 => 'WARN',
3 => 'INFO',
4 => 'DEBUG'
)

Definition at line 50 of file Logger.php.


The documentation for this class was generated from the following file: