broken-link-checker
Last commit date
css
16 years ago
images
16 years ago
includes
15 years ago
js
16 years ago
languages
15 years ago
JSON.php
17 years ago
broken-link-checker.php
15 years ago
config-manager.php
16 years ago
core.php
15 years ago
logger.php
16 years ago
readme.txt
15 years ago
uninstall.php
16 years ago
utility-class.php
16 years ago
logger.php
153 lines
| 1 | <?php |
| 2 | |
| 3 | //TODO: Add comments |
| 4 | |
| 5 | if ( !class_exists('blcLogger') ): |
| 6 | |
| 7 | define('BLC_LEVEL_DEBUG', 0); |
| 8 | define('BLC_LEVEL_INFO', 1); |
| 9 | define('BLC_LEVEL_WARNING', 2); |
| 10 | define('BLC_LEVEL_ERROR', 3); |
| 11 | |
| 12 | class blcLogger { |
| 13 | |
| 14 | function __construct($param = ''){ |
| 15 | |
| 16 | } |
| 17 | |
| 18 | function blcLogger($param = ''){ |
| 19 | $this->__construct($param); |
| 20 | } |
| 21 | |
| 22 | function log($message, $object = null, $level = BLC_LEVEL_DEBUG){ |
| 23 | |
| 24 | } |
| 25 | |
| 26 | function debug($message, $object = null){ |
| 27 | $this->log($message, $object, BLC_LEVEL_DEBUG); |
| 28 | } |
| 29 | |
| 30 | function info($message, $object = null){ |
| 31 | $this->log($message, $object, BLC_LEVEL_INFO); |
| 32 | } |
| 33 | |
| 34 | function warn($message, $object = null){ |
| 35 | $this->log($message, $object, BLC_LEVEL_WARNING); |
| 36 | } |
| 37 | |
| 38 | function error($message, $object = null){ |
| 39 | $this->log($message, $object, BLC_LEVEL_ERROR); |
| 40 | } |
| 41 | |
| 42 | function get_messages($min_level = BLC_LEVEL_DEBUG){ |
| 43 | return array(); |
| 44 | } |
| 45 | |
| 46 | function get_log($min_level = BLC_LEVEL_DEBUG){ |
| 47 | return array(); |
| 48 | } |
| 49 | |
| 50 | function clear(){ |
| 51 | |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | class blcOptionLogger extends blcLogger{ |
| 56 | |
| 57 | var $option_name = ''; |
| 58 | var $filter_level = 0; |
| 59 | |
| 60 | function __construct( $option_name = '' ){ |
| 61 | $this->option_name = $option_name; |
| 62 | } |
| 63 | |
| 64 | function log($message, $object = null, $level = BLC_LEVEL_DEBUG){ |
| 65 | $current = get_option($this->option_name); |
| 66 | $new_entry = array($level, $message, $object); |
| 67 | |
| 68 | if ( empty($current) ){ |
| 69 | $current = array( $new_entry ); |
| 70 | } else { |
| 71 | array_push($current, $new_entry); |
| 72 | } |
| 73 | |
| 74 | update_option($this->option_name, $current); |
| 75 | } |
| 76 | |
| 77 | function get_log($min_level = BLC_LEVEL_DEBUG){ |
| 78 | $log = get_option($this->option_name); |
| 79 | if ( empty($log) || !is_array($log) ){ |
| 80 | return array(); |
| 81 | } |
| 82 | |
| 83 | $this->filter_level = $min_level; |
| 84 | return array_filter($log, array($this, '_filter_log')); |
| 85 | } |
| 86 | |
| 87 | function _filter_log($entry){ |
| 88 | return ( $entry[0] >= $this->filter_level ); |
| 89 | } |
| 90 | |
| 91 | function get_messages($min_level = BLC_LEVEL_DEBUG){ |
| 92 | $messages = $this->get_log($min_level); |
| 93 | return array_map( array($this, '_get_log_message'), $messages ); |
| 94 | } |
| 95 | |
| 96 | function _get_log_message($entry){ |
| 97 | return $entry[1]; |
| 98 | } |
| 99 | |
| 100 | function clear(){ |
| 101 | delete_option($this->option_name); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | class blcMemoryLogger extends blcLogger { |
| 106 | |
| 107 | var $log; |
| 108 | var $name = ''; |
| 109 | var $filter_level = BLC_LEVEL_DEBUG; |
| 110 | |
| 111 | |
| 112 | function __construct($name = ''){ |
| 113 | $this->name = $name; |
| 114 | $this->log = array(); |
| 115 | } |
| 116 | |
| 117 | function log($message, $object = null, $level = BLC_LEVEL_DEBUG){ |
| 118 | $new_entry = array($level, $message, $object); |
| 119 | array_push($this->log, $new_entry); |
| 120 | } |
| 121 | |
| 122 | function get_log($min_level = BLC_LEVEL_DEBUG){ |
| 123 | $this->filter_level = $min_level; |
| 124 | return array_filter($this->log, array($this, '_filter_log')); |
| 125 | } |
| 126 | |
| 127 | function _filter_log($entry){ |
| 128 | return ( $entry[0] >= $this->filter_level ); |
| 129 | } |
| 130 | |
| 131 | function get_messages($min_level = BLC_LEVEL_DEBUG){ |
| 132 | $messages = $this->get_log($min_level); |
| 133 | return array_map( array($this, '_get_log_message'), $messages ); |
| 134 | } |
| 135 | |
| 136 | function _get_log_message($entry){ |
| 137 | return $entry[1]; |
| 138 | } |
| 139 | |
| 140 | function clear(){ |
| 141 | $this->log = array(); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | class blcDummyLogger extends blcLogger { |
| 146 | |
| 147 | } |
| 148 | |
| 149 | endif; |
| 150 | |
| 151 | |
| 152 | |
| 153 | ?> |