Last active
December 30, 2015 08:39
-
-
Save tskrynnyk/7804190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Logger { | |
| private static $file = '../log/app.log'; | |
| private static function log($level, $msg) { | |
| $keys = array( | |
| 'HTTP_HOST', | |
| 'REDIRECT_STATUS', | |
| 'REQUEST_METHOD', | |
| 'REMOTE_ADDR', | |
| 'HTTP_VIA', | |
| 'HTTP_X_FORWARDED_FOR', | |
| 'HTTP_USER_AGENT', | |
| 'HTTP_X_VARNISH', | |
| 'HTTP_ACCEPT', | |
| 'HTTP_ACCEPT_LANGUAGE', | |
| 'REQUEST_URI', | |
| 'QUERY_STRING' | |
| ); | |
| foreach ($keys as $key) { | |
| if (array_key_exists($key, $_SERVER) && !empty($_SERVER[$key])) | |
| $params[$key] = $_SERVER[$key]; | |
| } | |
| $log = '"' . join("\" \"", $params) . '"'; | |
| if (!empty($msg)) | |
| $log .= ' "' . $msg . '"'; | |
| $f = fopen(self::$file, 'a'); | |
| fwrite($f, sprintf("%s [%s] %s\n", date("Y-m-d H:i:s"), $level, $log)); | |
| fclose($f); | |
| } | |
| public static function error($msg = '') { | |
| self::log('error', $msg); | |
| } | |
| public static function warn($msg = '') { | |
| self::log('warn', $msg); | |
| } | |
| public static function info($msg = '') { | |
| self::log('info', $msg); | |
| } | |
| public static function debug($msg = '') { | |
| self::log('debug', $msg); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment