81 $this->directory = rtrim($realPath,
'/') .
'/';
83 $this->directory =
false;
102 $theLevel = (int)$level;
103 if ( $theLevel >= 0 && $theLevel <= 4 ) {
104 $this->level = $theLevel;
106 throw new InvalidArgumentException(
'Invalid Log Level. Must be one of: 0, 1, 2, 3, 4.');
124 $this->
log($data, 4);
132 public function info( $data ) {
133 $this->
log($data, 3);
141 public function warn( $data ) {
142 $this->
log($data, 2);
151 $this->
log($data, 1);
160 $this->
log($data, 0);
168 return $this->
getDirectory() . strftime(
'%Y-%m-%d') .
'.log';
178 protected function log( $data, $level ) {
180 if ( $dir ==
false || !is_dir($dir) ) {
181 throw new RuntimeException(
"Log directory '$dir' invalid.");
183 if ( !is_writable($dir) ) {
184 throw new RuntimeException(
"Log directory '$dir' not writable.");
186 if ( $level <= $this->
getLevel() ) {
187 $this->
write(sprintf(
"[%s] %s - %s\r\n", $this->levels[$level], date(
'c'), (
string)$data));
197 @file_put_contents($this->
getFile(), $data, FILE_APPEND | LOCK_EX);