PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / features / class-log.php

class-log.php in DecaLog 4.4.0, at includes/features/class-log.php

89 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * DecaLog logger utilities.
4 *
5 * @package Features
6 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
7 * @since 1.0.0
8 */
9
10 namespace Decalog\Plugin\Feature;
11
12 use Decalog\Plugin\Feature\DLogger;
13 use DLMonolog\Logger;
14 use Decalog\Plugin\Feature\EventTypes;
15
16
17 /**
18 * Utilities DecaLog class.
19 *
20 * This class defines all code necessary to log events with DecaLog.
21 *
22 * @package Features
23 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
24 * @since 1.0.0
25 */
26 class Log {
27
28 /**
29 * Initialize the class and set its properties.
30 *
31 * @since 1.0.0
32 */
33 public function __construct() {
34 }
35
36 /**
37 * Get a new logger instance.
38 *
39 * @param string $class The class identifier, see Decalog\API\DLogger::$classes.
40 * @param string $name Optional. The name of the component.
41 * @param string $version Optional. The version of the component.
42 * @param string $test Optional. The handler to bootstrap if specified..
43 * @return DLogger The DecaLog logger instance.
44 * @since 1.0.0
45 */
46 public static function bootstrap( $class, $name = null, $version = null, $test = null ) {
47 return new DLogger( $class, $name, $version, $test );
48 }
49
50 /**
51 * Get a level name.
52 *
53 * @param integer $level The level value.
54 * @return string The level name.
55 * @since 1.0.0
56 */
57 public static function level_name( $level ) {
58 $result = 'UNKNOWN';
59 if ( array_key_exists( $level, EventTypes::$level_names ) ) {
60 $result = EventTypes::$level_names[ $level ];
61 }
62 return $result;
63 }
64
65 /**
66 * Get the levels list.
67 *
68 * @param integer $minimal Optional. The minimal level to add.
69 * @param boolean $warn Optional. Adds a warning to the DEBUG string.
70 * @return array The level list.
71 * @since 1.0.0
72 */
73 public static function get_levels( $minimal = Logger::DEBUG, $warn = false ) {
74 $result = [];
75 $warning = ' (' . decalog_esc_html__( 'use this only if you know what you do', 'decalog' ) . ')';
76 foreach ( EventTypes::$level_names as $key => $name ) {
77 if ( $key >= $minimal ) {
78 if ( Logger::DEBUG == $key && $warn) {
79 $result[] = [ $key, $name . $warning, EventTypes::$level_texts[ strtolower( $name ) ] . $warning ];
80 } else {
81 $result[] = [ $key, $name, EventTypes::$level_texts[ strtolower( $name ) ] ];
82 }
83 }
84 }
85 return array_reverse( $result );
86 }
87
88 }
89