[18220] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 4 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 5 | * this work for additional information regarding copyright ownership. |
---|
| 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 7 | * (the "License"); you may not use this file except in compliance with |
---|
| 8 | * the License. You may obtain a copy of the License at |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, software |
---|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | * See the License for the specific language governing permissions and |
---|
| 16 | * limitations under the License. |
---|
| 17 | * |
---|
| 18 | * |
---|
| 19 | * @package log4php |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | /** |
---|
| 23 | * @ignore |
---|
| 24 | */ |
---|
| 25 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * Helper class for internal logging |
---|
| 29 | * |
---|
| 30 | * <p>It uses php {@link PHP_MANUAL#trigger_error trigger_error()} function |
---|
| 31 | * to output messages.</p> |
---|
| 32 | * <p>You need to recode methods to output messages in a different way.</p> |
---|
| 33 | * |
---|
| 34 | * @author Marco Vassura |
---|
| 35 | * @version $Revision: 635069 $ |
---|
| 36 | * @package log4php |
---|
| 37 | */ |
---|
| 38 | class LoggerLog { |
---|
| 39 | |
---|
| 40 | protected static $debug = false; |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * Log if debug is enabled. |
---|
| 44 | * |
---|
| 45 | * Log using php {@link PHP_MANUAL#trigger_error trigger_error()} function |
---|
| 46 | * with E_USER_NOTICE level by default. |
---|
| 47 | * |
---|
| 48 | * @param string $message log message |
---|
| 49 | * @param integer $errLevel level to log |
---|
| 50 | * @static |
---|
| 51 | */ |
---|
| 52 | public static function log($message, $errLevel = E_USER_NOTICE) |
---|
| 53 | { |
---|
| 54 | if (LoggerLog::internalDebugging()) |
---|
| 55 | trigger_error($message, $errLevel); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | public static function internalDebugging($value = null) |
---|
| 59 | { |
---|
| 60 | if (is_bool($value)) |
---|
| 61 | self::$debug = $value; |
---|
| 62 | return self::$debug; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * Report a debug message. |
---|
| 67 | * |
---|
| 68 | * @param string $message log message |
---|
| 69 | * @static |
---|
| 70 | * @since 0.3 |
---|
| 71 | */ |
---|
| 72 | public static function debug($message) |
---|
| 73 | { |
---|
| 74 | LoggerLog::log($message, E_USER_NOTICE); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | * Report an error message. |
---|
| 79 | * |
---|
| 80 | * @param string $message log message |
---|
| 81 | * @static |
---|
| 82 | * @since 0.3 |
---|
| 83 | */ |
---|
| 84 | public static function error($message) |
---|
| 85 | { |
---|
| 86 | trigger_error($message, E_USER_ERROR); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * Report a warning message. |
---|
| 91 | * |
---|
| 92 | * @param string $message log message |
---|
| 93 | * @static |
---|
| 94 | * @since 0.3 |
---|
| 95 | */ |
---|
| 96 | public static function warn($message) |
---|
| 97 | { |
---|
| 98 | trigger_error($message, E_USER_WARNING); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | } |
---|