-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.txt
190 lines (118 loc) · 5.8 KB
/
README.txt
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
PHPDebugr
=========
A debugging tool for inspecting variables.
A quick and effective debugging tool/solution if you do not have access to (or don't want to use) a single-stepping debugger like xdebug. Powerful 'var_dump' replacement with logging capabilities and console support.
Usage
-----
Debugr::eDbg(mixed $var [, string $description [, string $writeOption]])
Debugr::eDbg writes the value of $var and the $description text (optional) to the output, defined in config.php, using the $writeOption. Possible options for the output are: Screen, Log, Console, and None.
(The predefined value is Screen)
Debugr::eDbgScreen(mixed $var [, string $description [, string $writeOption]])
Debugr::eDbgScreen writes the value of $var to the screen regardless of the default config.php file entry.
Debugr::eDbgLog(mixed $var [, string $description [, string $writeOption [, sting|null $logFile]])
Debugr::eDbgLog writes the value of $var to the log file defined in config.php, set through Debugr::setLogfile() or passed through the $logFile parameter.
Debugr::eDbgConsole(mixed $var [, string $description [, string $writeOption]])
Debugr::eDbgConsole writes the value of $var to the browsers console.
Debugr::setLogFile(string $logFile)
Debugr::setLogFile sets the log file, overwriting the config.php file option.
Parameters
var
The variable to inspect
description (optional)
Text to be displayed before the variable value e.g. The value of $thisVar is:
writeOption (optional)
The way the output is written/formatted
options:
'e' or 'echoes' – for echo-like output
'v' or 'varDump' – for var_dump-like output
'r' or 'printR' – for print_r-like output
'x' or 'export' – for var_export-like output
If you omit this the defaults are used. For scalar types (integer, double, string) the default is echoes and for composite types (array, object, resource, boolean, null, unknown type) the default is varDump. The defaults can be changed in the config.php file.
(I know boolean is technically scalar and Null is, well, Null, but they are fitting better in the composite group)
Logging
-----
Output can be logged to a file by specifying Log as output in config.php or by calling Debugr::eDbgLog() directly.
The log file used can be defined as follows:
options:
Configuration option inconfig.php
The default option. Predefined as output.log.
Through Debugr::setLogfile()
Takes precedence over the config.php option.
As 4th parameter of Debugr::eDbgLog()
Has the highest priority. Is only set for this call.
(See example below)
Notes
-----
If None is used as the default output, Debugr::eDbg will not produce any output. This is not true for eDbgScreen, eDbgLog, eDbgConsole. You can disable all by setting: disable:true in config.php. This is some sort of kill switch.
Install
-----
Composer or no composer? That is the question!
composer:
composer require nikoutel/phpdebugr
no composer:
Just dump the files in you project and use as shown below.
require('path/to/Debugr/src/Debugr.php');
use Nikoutel\Debugr\Debugr;
How to use
----------
Use eDbg to output the variable values to the default output. On a developer server you can choose Screen. If you have to use it on a production server use Log and all Debugr::eDbg calls will now write to the log file instead of the screen.
On some occasions e.g. when outputting a variable on screen breaks the site layout you can use eDbgConsole to use the browser console regardless of the default output. In the same way you can use eDbgScreen, eDbgLog, according to the situation and your needs.
The value is formatted according to the variables type or the writeOption given.
Requirements
------------
* PHP 5.3 (min)
* (optional) The "Multibyte String" php extension (mbstring) - Allows multibyte characters to be used in log filenames
Examples
--------
// composer:
require __DIR__ . '/vendor/autoload.php';
use Nikoutel\Debugr\Debugr;
// no composer:
require('path/to/Debugr/src/Debugr.php');
use Nikoutel\Debugr\Debugr;
$varB = 42;
Debugr::edbg($varB);
42
$varC = 103993/33102;
Debugr::edbg($varC, 'the value of pi is');
the value of pi is: 3.1415926530119
$varA = 'Guru Meditation';
Debugr::edbg($varA, NULL, 'v');
string(15) "Guru Meditation"
$varE = array( 'black jack', 'gin rummy', 'hearts', 'bridge', 'checkers', 'chess', 'global thermonuclear war');
Debugr::edbg($varE, 'Shall we play a game?','r');
Shall we play a game?:
Array
(
[0] => black jack
[1] => gin rummy
[2] => hearts
[3] => bridge
[4] => checkers
[5] => chess
[6] => global thermonuclear war
)
$varF = fopen('secretFile.xml', 'r');
Debugr::edbgLog($varF);
fclose($varF);
Debugr::edbgLog($varF);
will produce a log file entry:
(18/10/2017 17:23:58) /LondonBlue/Secret/getSecret.php
resource(19) of type (stream)
(18/10/2017 17:23:58) /LondonBlue/Secret/getSecret.php
resource(19) of type (Unknown)
Debugr::edbgLog($varG); # writes to output.log defined in config.php
Debugr::setLogFile(newOutput.log);
Debugr::edbgLog($varH); # writes to newOutput.log
Debugr::edbgLog($varI, 'v', 'prioOutput.log'); # writes to prioOutput.log
Debugr::edbgLog($varJ); # writes to newOutput.log
$book = new stdClass;
$book->php = 'PHP Design Patterns, Stephan Schmidt';
$book->c = 'The C Programming Language, Kernighan & Ritchie';
$book->unix = 'The unix programming environment, Kernighan & Pike';
$book->economics = 'Making Millions For Dummies';
Debugr::edbgConsole($book, '$book');
will produce a console output
License
-------
This software is licensed under the MPL 2.0: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.