/
Action_Logger.php
125 lines (113 loc) · 2.33 KB
/
Action_Logger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Hooks the `tribe_log` action based logger under the existing one for back-compatibility.
*
* @since 4.9.16
*
* @package Tribe\Log
*/
namespace Tribe\Log;
use TEC\Common\Monolog\Logger;
use Tribe__Log;
/**
* Class Action_Logger
*
* @since 4.9.16
*
* @package Tribe\Log
*/
class Action_Logger implements \Tribe__Log__Logger {
/**
* {@inheritDoc}
*
* @since 4.9.16
*/
public function is_available() {
return true;
}
/**
* {@inheritDoc}
*
* @since 4.9.16
*/
public function get_name() {
return __( 'Action-based Logger', 'tribe-common' );
}
/**
* {@inheritDoc}
*
* @since 4.9.16
*/
public function log( $entry, $type = Tribe__Log::DEBUG, $src = '' ) {
$message = empty( $src ) ? $entry : $src . ': ' . $entry;
do_action( 'tribe_log', $this->translate_log_level( $type ), $message );
}
/**
* Translates the log types used by `Tribe__Log` to those used by Monolog.
*
* @since 4.9.16
*
* @param string $type The `Tribe__Log` log type.
*
* @return int The Monolog equivalent of the current level.
*/
protected function translate_log_level( $type ) {
switch ( $type ) {
case Tribe__Log::DEBUG:
return Logger::DEBUG;
case Tribe__Log::ERROR:
return Logger::ERROR;
case Tribe__Log::WARNING:
return Logger::WARNING;
case Tribe__Log::SUCCESS:
default:
return Logger::INFO;
}
}
/**
* {@inheritDoc}
*
* @since 4.9.16
*/
public function retrieve( $limit = 0, array $args = [] ) {
return [
[
'message' => __(
'The Action Logger will dispatch any logging message using the "tribe_log" action writing, by ' .
'default, to the PHP error log.',
'tribe-common' )
],
];
}
/**
* {@inheritDoc}
*
* @since 4.9.16
*/
public function list_available_logs() {
return [];
}
/**
* Changes the Monolog logger channel to the specified one.
*
* @since 4.9.16
*
* @param string $log_identifier The channel to switch to.
* @param bool $create Unused by this class.
*
* @return bool The exit status of the channel change.
*
* @uses \Tribe\Log\Monolog_Logger::set_channel().
*/
public function use_log( $log_identifier, $create = false ) {
return tribe( 'monolog' )->set_global_channel( $log_identifier );
}
/**
* {@inheritDoc}
*
* @since 4.9.16
*/
public function cleanup() {
return true;
}
}