/ Published in: PHP
This class can log messages to a file. If the log file becomes too large (over 1MB), the class will archive it and will create new. If there are archives older than one month, they will be deleted automatically.
In the future versions I will add the opportunity to set max log size and max time to keep the archives.
In the future versions I will add the opportunity to set max log size and max time to keep the archives.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class logger { private $file; private $error = false; function __construct($file) { $this->error = 'Can\'t rename the old log file'; } //ако има Ñтари логове на повече от 1 меÑец } } } } } function log_start() { $this->error = 'Can\'t write to log'; } } function log_message($message) { $message = $message.PHP_EOL; $this->error = 'Can\'t write to log'; } } function log_end() { $msg_end .= '-------------------------------'.PHP_EOL; $this->error = 'Can\'t write to log'; } } function is_error() { if($this->error != false) { return true; } return false; } function get_error() { return $this->error; } } /* example usage $log = new logger('/path/to/log.txt'); //if file doesnt exiists, will be created $log->log_start(); //this will insert timestap to mark the beginning if($sallary < $work) { $log->log_message('Not acceptable sallary/work ratio'); } $log->log_end(); //this will insert timestap to mark the end of current log */ ?>