PluginProbe
Manage – Centralized site maintenance and monitoring / trunk
Manage – Centralized site maintenance and monitoring vtrunk
1.0.9 1.0.8 1.0.7 1.0.6 1.0.5 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4
manage / classes / logger.php

logger.php in Manage – Centralized site maintenance and monitoring trunk, at classes/logger.php

37 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Manage\Classes;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 class Logger {
9 public const LEVEL_ERROR = 'error';
10 public const LEVEL_WARN = 'warn';
11 public const LEVEL_INFO = 'info';
12
13 private static function log( string $log_level, $message ): void {
14 $backtrace = debug_backtrace(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
15
16 $class = $backtrace[2]['class'] ?? null;
17 $type = $backtrace[2]['type'] ?? null;
18 $function = $backtrace[2]['function'];
19
20 if ( $class ) {
21 $message = '[MANAGE]: ' . $log_level . ' in ' . "$class$type$function()" . ': ' . $message;
22 } else {
23 $message = '[MANAGE]: ' . $log_level . ' in ' . "$function()" . ': ' . $message;
24 }
25
26 error_log( $message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
27 }
28
29 public static function error( $message ): void {
30 self::log( self::LEVEL_ERROR, $message );
31 }
32
33 public static function info( $message ): void {
34 self::log( self::LEVEL_INFO, $message );
35 }
36 }
37