1 | <?php // (C) Copyright Bobbing Wide 2011-2015 |
---|
2 | if ( !defined( "BWTRACE_INCLUDED" ) ) { |
---|
3 | define( "BWTRACE_INCLUDED", "2.0.5" ); |
---|
4 | define( "BWTRACE_FILE", __FILE__ ); |
---|
5 | |
---|
6 | /** |
---|
7 | * Trace library functions |
---|
8 | * |
---|
9 | * Library: bwtrace |
---|
10 | * Provides: bwtrace |
---|
11 | * Type: MU |
---|
12 | * |
---|
13 | */ |
---|
14 | |
---|
15 | /** |
---|
16 | * Constants for bw_trace2's $level parameter |
---|
17 | * |
---|
18 | * - The trace record is produced if the $level passed is greater than or equal to the current tracing level ( $bw_trace_on ); |
---|
19 | * - The default value for bw_trace2 is BW_TRACE_ALWAYS |
---|
20 | * - The higher you set the value the more tracing you get. |
---|
21 | * - The testing is NOT (yet) implemented as a bit-mask. |
---|
22 | * - Note: These values are a subset of logging levels in packages such as monolog. |
---|
23 | * - It's not really necessary to have CRITICAL, ALERT or EMERGENCY; ERROR will suffice |
---|
24 | * - See also {@link https://en.wikipedia.org/wiki/Syslog#Severity_levels} |
---|
25 | * |
---|
26 | */ |
---|
27 | if ( !defined( 'BW_TRACE_DEBUG' ) ) { define( 'BW_TRACE_DEBUG', 32 ); } |
---|
28 | if ( !defined( 'BW_TRACE_INFO' ) ) { define( 'BW_TRACE_INFO', 16 ); } // recommended level |
---|
29 | if ( !defined( 'BW_TRACE_NOTICE' ) ) { define( 'BW_TRACE_NOTICE', 8 ); } |
---|
30 | if ( !defined( 'BW_TRACE_WARNING' ) ) { define( 'BW_TRACE_WARNING', 4 ); } |
---|
31 | if ( !defined( 'BW_TRACE_ERROR' ) ) { define( 'BW_TRACE_ERROR', 2 ); } |
---|
32 | if ( !defined( 'BW_TRACE_ALWAYS' ) ) { define( 'BW_TRACE_ALWAYS', 0 ); } // bw_trace2() default |
---|
33 | |
---|
34 | /** |
---|
35 | * Assume tracing is off |
---|
36 | */ |
---|
37 | if ( !isset( $bw_trace_on )) { |
---|
38 | if ( defined( 'BW_TRACE_ON' ) ) { |
---|
39 | $bw_trace_on = BW_TRACE_ON; |
---|
40 | } else { |
---|
41 | $bw_trace_on = false; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * Only set trace level if BW_TRACE_LEVEL is defined and it's not already set |
---|
47 | */ |
---|
48 | if ( !isset( $bw_trace_level )) { |
---|
49 | if ( defined( 'BW_TRACE_LEVEL' ) ) { |
---|
50 | $bw_trace_level = BW_TRACE_LEVEL; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * Log a simple trace record to the trace log file if tracing is active |
---|
57 | * |
---|
58 | * Use bw_trace2() in preference to bw_trace() except in special circumstances |
---|
59 | * which prevent bw_trace2() from being invoked. |
---|
60 | * |
---|
61 | * @param mixed $text value to be traced |
---|
62 | * @param string $function name of function to log in the trace file |
---|
63 | * @param integer $lineno line number of source file to log |
---|
64 | * @param string $file source file name |
---|
65 | * @param string $text_label a label to help you locate the trace record |
---|
66 | * |
---|
67 | */ |
---|
68 | if ( !function_exists( "bw_trace" ) ) { |
---|
69 | function bw_trace( $text, $function=__FUNCTION__, $lineno=__LINE__, $file=__FILE__, $text_label=NULL) { |
---|
70 | global $bw_trace_on; |
---|
71 | if ( $bw_trace_on ) { |
---|
72 | bw_lazy_trace( $text, $function, $lineno, $file, $text_label ); |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * Trace $value to the trace log file if tracing is active |
---|
79 | * |
---|
80 | * @param mixed $value - the value to be traced. |
---|
81 | * The value can be a simple field, array or complex object such as a post |
---|
82 | * @param string $text - additional information |
---|
83 | * @param bool $show_args - true if the parameter values are to be traced, false otherwise |
---|
84 | * @param integer $level - the trace level requested |
---|
85 | * @return mixed $value - the first parameter |
---|
86 | */ |
---|
87 | if ( !function_exists( "bw_trace2" ) ) { |
---|
88 | function bw_trace2( $value=NULL, $text=NULL, $show_args=true, $level=BW_TRACE_ALWAYS ) { |
---|
89 | global $bw_trace_on, $bw_trace_level; |
---|
90 | if ( $bw_trace_on && ( $level <= $bw_trace_level ) ) { |
---|
91 | return( bw_lazy_trace2( $value, $text, $show_args, $level )); |
---|
92 | } else { |
---|
93 | return( $value ); |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Log a debug_backtrace() to the trace log file if tracing is active |
---|
100 | * |
---|
101 | */ |
---|
102 | if ( !function_exists( "bw_backtrace" ) ) { |
---|
103 | function bw_backtrace( $level=BW_TRACE_ALWAYS ) { |
---|
104 | global $bw_trace_on, $bw_trace_level; |
---|
105 | if ( $bw_trace_on && ( $level <= $bw_trace_level ) ) { |
---|
106 | bw_lazy_backtrace(); |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | * Start up tracing from the wp-config file if required |
---|
113 | * |
---|
114 | * Only do this if the file is available from the current library |
---|
115 | */ |
---|
116 | if ( defined( 'BW_TRACE_CONFIG_STARTUP' ) && BW_TRACE_CONFIG_STARTUP == true ) { |
---|
117 | $bwtrace_boot = __DIR__ . '/bwtrace_boot.php'; |
---|
118 | if ( file_exists( $bwtrace_boot ) ) { |
---|
119 | require_once( $bwtrace_boot ); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | } /* end !defined */ |
---|