ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Slim_Logger Class Reference
+ Collaboration diagram for Slim_Logger:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

 $levels
 
 $directory
 

Detailed Description

Definition at line 45 of file Logger.php.

Constructor & Destructor Documentation

◆ __construct()

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().

68  {
69  $this->setDirectory($directory);
70  $this->setLevel($level);
71  }
setLevel( $level)
Set log level.
Definition: Logger.php:101
setDirectory( $directory)
Set log directory.
Definition: Logger.php:78
+ Here is the call graph for this function:

Member Function Documentation

◆ debug()

Slim_Logger::debug (   $data)

Log debug data.

Parameters
mixed$data
Returns
void

Definition at line 123 of file Logger.php.

References $data, and log().

123  {
124  $this->log($data, 4);
125  }
log( $data, $level)
Log data to file.
Definition: Logger.php:178
+ Here is the call graph for this function:

◆ error()

Slim_Logger::error (   $data)

Log error data.

Parameters
mixed$data
Returns
void

Definition at line 150 of file Logger.php.

References $data, and log().

150  {
151  $this->log($data, 1);
152  }
log( $data, $level)
Log data to file.
Definition: Logger.php:178
+ Here is the call graph for this function:

◆ fatal()

Slim_Logger::fatal (   $data)

Log fatal data.

Parameters
mixed$data
Returns
void

Definition at line 159 of file Logger.php.

References $data, and log().

159  {
160  $this->log($data, 0);
161  }
log( $data, $level)
Log data to file.
Definition: Logger.php:178
+ Here is the call graph for this function:

◆ getDirectory()

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().

91  {
92  return $this->directory;
93  }
+ Here is the caller graph for this function:

◆ getFile()

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().

167  {
168  return $this->getDirectory() . strftime('%Y-%m-%d') . '.log';
169  }
getDirectory()
Get log directory.
Definition: Logger.php:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLevel()

Slim_Logger::getLevel ( )

Get log level.

Returns
int

Definition at line 114 of file Logger.php.

Referenced by log().

114  {
115  return $this->level;
116  }
+ Here is the caller graph for this function:

◆ info()

Slim_Logger::info (   $data)

Log info data.

Parameters
mixed$data
Returns
void

Definition at line 132 of file Logger.php.

References $data, and log().

132  {
133  $this->log($data, 3);
134  }
log( $data, $level)
Log data to file.
Definition: Logger.php:178
+ Here is the call graph for this function:

◆ log()

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 $data, date, getDirectory(), getLevel(), levels, and write().

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

178  {
179  $dir = $this->getDirectory();
180  if ( $dir == false || !is_dir($dir) ) {
181  throw new RuntimeException("Log directory '$dir' invalid.");
182  }
183  if ( !is_writable($dir) ) {
184  throw new RuntimeException("Log directory '$dir' not writable.");
185  }
186  if ( $level <= $this->getLevel() ) {
187  $this->write(sprintf("[%s] %s - %s\r\n", $this->levels[$level], date('c'), (string)$data));
188  }
189  }
write( $data)
Persist data to log.
Definition: Logger.php:196
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
getLevel()
Get log level.
Definition: Logger.php:114
getDirectory()
Get log directory.
Definition: Logger.php:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDirectory()

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().

78  {
79  $realPath = realpath($directory);
80  if ( $realPath ) {
81  $this->directory = rtrim($realPath, '/') . '/';
82  } else {
83  $this->directory = false;
84  }
85  }
+ Here is the caller graph for this function:

◆ setLevel()

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().

101  {
102  $theLevel = (int)$level;
103  if ( $theLevel >= 0 && $theLevel <= 4 ) {
104  $this->level = $theLevel;
105  } else {
106  throw new InvalidArgumentException('Invalid Log Level. Must be one of: 0, 1, 2, 3, 4.');
107  }
108  }
+ Here is the caller graph for this function:

◆ warn()

Slim_Logger::warn (   $data)

Log warn data.

Parameters
mixed$data
Returns
void

Definition at line 141 of file Logger.php.

References $data, and log().

141  {
142  $this->log($data, 2);
143  }
log( $data, $level)
Log data to file.
Definition: Logger.php:178
+ Here is the call graph for this function:

◆ write()

Slim_Logger::write (   $data)
protected

Persist data to log.

Parameters
stringLog message
Returns
void

Definition at line 196 of file Logger.php.

References $data, and getFile().

Referenced by log().

196  {
197  @file_put_contents($this->getFile(), $data, FILE_APPEND | LOCK_EX);
198  }
getFile()
Get absolute path to current daily log file.
Definition: Logger.php:167
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $directory

Slim_Logger::$directory
protected

Definition at line 61 of file Logger.php.

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

◆ $levels

Slim_Logger::$levels
protected
Initial value:
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: