|
1
|
|
|
<?php
|
|
2
|
|
|
/**
|
|
3
|
|
|
* Méthodes utiles pour les logs
|
|
4
|
|
|
*
|
|
5
|
|
|
* @author Eoxia <[email protected]>
|
|
6
|
|
|
* @since 1.0.0
|
|
7
|
|
|
* @version 1.0.0
|
|
8
|
|
|
* @copyright 2015-2018 Eoxia
|
|
9
|
|
|
* @package EO_Framework\Core\Util
|
|
10
|
|
|
*/
|
|
11
|
|
|
|
|
12
|
|
|
namespace eoxia;
|
|
13
|
|
|
|
|
14
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
15
|
|
|
exit;
|
|
16
|
|
|
}
|
|
17
|
|
|
|
|
18
|
|
|
if ( ! class_exists( '\eoxia\LOG_Util' ) ) {
|
|
19
|
|
|
define( 'EO_NOTICE', 'EO_NOTICE' );
|
|
20
|
|
|
define( 'EO_RESPONSE_ERROR', 'EO_RESPONSE_ERROR' );
|
|
21
|
|
|
define( 'EO_RESPONSE_SUCCESS', 'EO_RESPONSE_SUCCESS' );
|
|
22
|
|
|
|
|
23
|
|
|
/**
|
|
24
|
|
|
* Méthodes utiles pour les logs.
|
|
25
|
|
|
*/
|
|
26
|
|
|
class LOG_Util extends \eoxia\Singleton_Util { |
|
27
|
|
|
|
|
28
|
|
|
/**
|
|
29
|
|
|
* Le constructeur est obligatoire pour utiliser la classe \eoxia\Singleton_Util
|
|
30
|
|
|
*/
|
|
31
|
|
|
protected function construct() {}
|
|
32
|
|
|
|
|
33
|
|
|
/**
|
|
34
|
|
|
* Méthode pour logguer.
|
|
35
|
|
|
*
|
|
36
|
|
|
* @since 1.3.0
|
|
37
|
|
|
* @version 1.3.0
|
|
38
|
|
|
*
|
|
39
|
|
|
* @param string $text Votre texte de log.
|
|
40
|
|
|
* @param string $file_name Le nom de votre fichier sans l'extension.
|
|
41
|
|
|
* @param string $level Le niveau d'erreur. Par défaut EO_NOTICE. {
|
|
42
|
|
|
* EO_NOTICE = Pour une informations
|
|
43
|
|
|
* EO_RESPONSE_ERROR = Si la réponse de la requête est une erreur.
|
|
44
|
|
|
* EO_RESPONSE_SUCCESS = Si la réponse de la requête est correcte.
|
|
45
|
|
|
* }.
|
|
46
|
|
|
*/
|
|
47
|
|
|
public static function log( $text, $file_name, $level = EO_NOTICE ) {
|
|
48
|
|
|
$bt = debug_backtrace();
|
|
49
|
|
|
|
|
50
|
|
|
if ( empty( $file_name ) ) {
|
|
51
|
|
|
self::log_wp_content( $text, $file_name, $level, $bt );
|
|
52
|
|
|
} else {
|
|
53
|
|
|
if ( false === ini_get( 'error_log' ) || '' == ini_get( 'error_log' ) ) {
|
|
54
|
|
|
self::log_wp_content( $text, $file_name, $level, $bt );
|
|
55
|
|
|
} else {
|
|
56
|
|
|
$path = dirname( ini_get( 'error_log' ) );
|
|
57
|
|
|
|
|
58
|
|
|
if ( ! is_dir( $path ) ) {
|
|
59
|
|
|
self::log_wp_content( $text, $file_name, $level, $bt );
|
|
60
|
|
|
} else {
|
|
61
|
|
|
error_log( current_time( '[d-M-Y H:i:s e]' ) . " PHP {$level}: {$text} in " . str_replace( '\\', '/', $bt[0]['file'] ) . " line {$bt[0]['line']}\n", 3, $path . '/' . $file_name . '.log' );
|
|
62
|
|
|
}
|
|
63
|
|
|
}
|
|
64
|
|
|
}
|
|
65
|
|
|
}
|
|
66
|
|
|
|
|
67
|
|
|
/**
|
|
68
|
|
|
* Méthode pour loggué dans un fichier dans le dossier 'wp-content/uploads' de WordPress.
|
|
69
|
|
|
*
|
|
70
|
|
|
* @since 1.3.0
|
|
71
|
|
|
* @version 1.3.0
|
|
72
|
|
|
*
|
|
73
|
|
|
* @param string $text Votre texte de log.
|
|
74
|
|
|
* @param string $file_name Le nom de votre fichier sans l'extension.
|
|
75
|
|
|
* @param string $level Le niveau d'erreur. Par défaut EO_NOTICE. {
|
|
76
|
|
|
* EO_NOTICE = Pour une informations
|
|
77
|
|
|
* EO_RESPONSE_ERROR = Si la réponse de la requête est une erreur.
|
|
78
|
|
|
* EO_RESPONSE_SUCCESS = Si la réponse de la requête est correcte.
|
|
79
|
|
|
* }.
|
|
80
|
|
|
* @param array $bt Le contexte de débogage.
|
|
81
|
|
|
*/
|
|
82
|
|
|
public static function log_wp_content( $text, $file_name, $level = EO_NOTICE, $bt = array() ) {
|
|
83
|
|
|
if ( empty( $bt ) ) {
|
|
84
|
|
|
$bt = debug_backtrace();
|
|
85
|
|
|
}
|
|
86
|
|
|
|
|
87
|
|
|
$wp_upload_dir = wp_upload_dir();
|
|
88
|
|
|
$file = fopen( $wp_upload_dir['path'] . '/' . $file_name . '.log', 'a' );
|
|
89
|
|
|
fwrite( $file, current_time( '[d-M-Y H:i:s e]' ) . " PHP {$level}: {$text} in " . str_replace( '\\', '/', $bt[0]['file'] ) . " line {$bt[0]['line']}\n" );
|
|
90
|
|
|
fclose( $file );
|
|
91
|
|
|
}
|
|
92
|
|
|
}
|
|
93
|
|
|
|
|
94
|
|
|
} // End if().
|
|
95
|
|
|
|