Skip to content

Commit eba308b

Browse files
committed
updated readme.md
1 parent 206aab6 commit eba308b

1 file changed

Lines changed: 88 additions & 52 deletions

File tree

readme.md

Lines changed: 88 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,54 @@
77
[![Latest Stable Version](https://poser.pugx.org/nette/tracy/v/stable)](https://github.com/nette/tracy/releases)
88
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/tracy/blob/master/license.md)
99

10-
Tracy library is a useful PHP everyday programmer's helper. It helps you to:
10+
Tracy library is a useful helper for everyday PHP programmers. It helps you to:
1111

1212
- quickly detect and correct errors
1313
- log errors
1414
- dump variables
15-
- measure the time
15+
- measure execution time of scripts/queries
16+
- see memory consumption
1617

1718

1819
PHP is a perfect language for making hardly detectable errors because it gives a great flexibility to programmers. Tracy\Debugger is more valuable because of that. It is a ultimate tool among the diagnostic ones.
1920
If you are meeting Tracy the first time, believe me, your life starts to be divided one before the Tracy and the one with her.
2021
Welcome to the good part!
2122

23+
24+
Installation and requirements
25+
-----------------------------
26+
2227
The best way how to install Tracy is to [download a latest package](https://github.com/nette/tracy/releases) or use a Composer:
2328

2429
```
2530
php composer.phar require tracy/tracy
2631
```
2732

28-
It is easy to activate Tracy. Preferably immediately after library loading (using `require 'src/tracy.php'` or via Composer) add code:
33+
Tracy requires PHP version 5.3.0 or newer (master requires PHP 5.6).
34+
35+
36+
Usage
37+
-----
38+
39+
Activating Tracy is easy. Simply add these two lines of code, preferably just after library loading (using `require 'src/tracy.php'` or via Composer):
2940

3041
```php
3142
use Tracy\Debugger;
3243

3344
Debugger::enable();
3445
```
3546

36-
The first thing you notice on the web site is a Debugger Bar.
47+
The first thing you will notice on the website is a Debugger Bar.
3748

3849

3950
Debugger Bar
4051
------------
4152

42-
The Debugger Bar is a floating panel. It is displayed in the bottom right corner of a page. You can move it by the mouse. It will remember its position after the page reloading.
53+
The Debugger Bar is a floating panel. It is displayed in the bottom right corner of a page. You can move it using the mouse. It will remember its position after the page reloading.
4354

44-
![Debugger-Bar](https://nette.github.io/tracy/images/tracy-bar.png)
55+
[![Debugger-Bar](https://nette.github.io/tracy/images/tracy-bar.png)](https://nette.github.io/tracy/tracy-debug-bar.html)
4556

46-
You can add other useful panels into the Debugger Bar.
57+
You can add other useful panels into the Debugger Bar. You can find interesing ones in [Addons](https://addons.nette.org) or you can create your own.
4758

4859

4960
Visualization of errors and exceptions
@@ -52,38 +63,35 @@ Visualization of errors and exceptions
5263
Surely, you know how PHP reports errors: there is something like this in the page source code:
5364

5465
```pre
55-
<b>Parse error</b>: syntax error, unexpected T_STRING in <b>SignPresenter.php</b> on line <b>6</b>
66+
<b>Parse error</b>: syntax error, unexpected '}' in <b>HomepagePresenter.php</b> on line <b>15</b>
5667
```
5768

5869
or uncaught exception:
5970

6071
```pre
61-
<b>Fatal error</b>: Uncaught exception 'Nette\Security\AuthenticationException' with message 'The password is incorrect.' in W:\examples\CD-collection\app\model\Authenticator.php:38
72+
<b>Fatal error</b>: Uncaught Nette\MemberAccessException: Call to undefined method Nette\Application\UI\Form::addTest()? in /sandbox/vendor/nette/utils/src/Utils/ObjectMixin.php:100
6273
Stack trace:
63-
#0 W:\Nette\Security\User.php(87): Authenticator-&gt;authenticate(Array)
64-
#1 W:\examples\CD-collection\app\presenters\SignPresenter.php(36): Nette\Security\User-&gt;login('demo', 'xx')
65-
#2 [internal function]: SignPresenter-&gt;signInFormSucceeded(Object(Nette\Application\UI\Form))
66-
#3 W:\Nette\Utils\Callback.php(38): call_user_func_array(Array, Array)
67-
#4 [internal function]: Nette\Utils\{closure}(Object(Nette\Application\UI\Form))
68-
#5 W:\Nette\Utils\Callback.php(50): call_user_func_array(Object(Closure), Array)
69-
#6 W:\Nette\Forms\Form.php(412): Nette\Utils\Callback::invoke(Object(Closure), Object(Nette\Application\UI\Form))
70-
#7 W:\Nette\Application\UI\Form.php(129): Nette\Forms\Form-&gt;fireEvents()
71-
#8 W:\Nette\Application\UI\Presenter.php(320): Nette\Application\UI in <b>W:\examples\CD-collection\app\model\Authenticator.php</b> on line <b>38</b><br />
74+
#0 /sandbox/vendor/nette/utils/src/Utils/Object.php(75): Nette\Utils\ObjectMixin::call(Object(Nette\Application\UI\Form), 'addTest', Array)
75+
#1 /sandbox/app/forms/SignFormFactory.php(32): Nette\Object-&gt;__call('addTest', Array)
76+
#2 /sandbox/app/presenters/SignPresenter.php(21): App\Forms\SignFormFactory-&gt;create()
77+
#3 /sandbox/vendor/nette/component-model/src/ComponentModel/Container.php(181): App\Presenters\SignPresenter-&gt;createComponentSignInForm('signInForm')
78+
#4 /sandbox/vendor/nette/component-model/src/ComponentModel/Container.php(139): Nette\ComponentModel\Container-&gt;createComponent('signInForm')
79+
#5 /sandbox/temp/cache/latte/15206b353f351f6bfca2c36cc.php(17): Nette\ComponentModel\Co in <b>/sandbox/vendor/nette/utils/src/Utils/ObjectMixin.php</b> on line <b>100</b><br />
7280
```
7381

74-
It is not so easy to navigate throw this output. If you enable the Tracy, errors or exceptions are displayed completely in a different form:
82+
It is not so easy to navigate through this output. If you enable Tracy, both errors and exceptions are displayed in a completely different form:
7583

7684
[![Uncaught exception rendered by Tracy](https://nette.github.io/tracy/images/tracy-exception.png)](https://nette.github.io/tracy/tracy-exception.html)
7785

7886
The error message literally screams. You can see a part of the source code with the highlighted line where the error occurred. A message clearly explains an error. The entire site is [interactive, try it](https://nette.github.io/tracy/tracy-exception.html).
7987

80-
And you know what? A fatal errors are captured and displayed in the same way. No need to install any extension (click for live example):
88+
And you know what? Fatal errors are captured and displayed in the same way. No need to install any extension (click for live example):
8189

8290
[![Fatal error rendered by Tracy](https://nette.github.io/tracy/images/tracy-error.png)](https://nette.github.io/tracy/tracy-error.html)
8391

84-
Errors like a typo in a variable name or an attempt to open a nonexistent file generate reports of E_NOTICE or E_WARNING level. These can be easily overlooked and/or can be completly hidden in a web page graphic layout. Let Tracy to manage them:
92+
Errors like a typo in a variable name or an attempt to open a nonexistent file generate reports of E_NOTICE or E_WARNING level. These can be easily overlooked and/or can be completely hidden in a web page graphic layout. Let Tracy manage them:
8593

86-
![Notice rendered by Tracy](https://nette.github.io/tracy/images/tracy-notice2.png)
94+
[![Notice rendered by Tracy](https://nette.github.io/tracy/images/tracy-notice2.png)](https://nette.github.io/tracy/tracy-debug-bar.html)
8795

8896
Or they may be displayed like errors:
8997

@@ -97,19 +105,19 @@ Debugger::$strictMode = TRUE;
97105
Production mode and error logging
98106
---------------------------------
99107

100-
As you can see, Tracy is quite eloquent. It is appreciated in a development environment, but on a production server it would cause disaster. There cannot be listed any debugging information. Therefore Tracy has an environment autodetection and logging functionality. Instead of showing self, Tracy stores information into log file and shows a server error with user-comprehensible message to visitor:
108+
As you can see, Tracy is quite eloquent. It is appreciated in a development environment, but on a production server it would cause a disaster. Any debugging information cannot be listed there. Therefore Tracy has an environment autodetection and logging functionality. Instead of showing herself, Tracy stores information into a log file and shows the visitor a user-comprehensible server error message:
101109

102-
![Server Error 500](https://nette.github.io/tracy/images/tracy-error2.png)
110+
[![Server Error 500](https://nette.github.io/tracy/images/tracy-error2.png)](https://nette.github.io/tracy/tracy-production.html)
103111

104-
An output mode suppresses all debugging information which are sent out via `Debugger::dump()` or `Debugger::fireLog()`, and of course all error messages generated by PHP. So, if you forget `Debugger::dump($obj)` in the source code, you do not have to worry about it on a production server. Nothing will be listed.
112+
Production output mode suppresses all debugging information which is sent out via `Debugger::dump()` or `Debugger::fireLog()`, and of course all error messages generated by PHP. So, even if you forget `Debugger::dump($obj)` in the source code, you do not have to worry about it on your production server. Nothing will be seen.
105113

106-
The output mode is switched by the first parameter of `Debugger::enable()`. You can specify either a constant `Debugger::PRODUCTION` or `Debugger::DEVELOPMENT`.
114+
The output mode is set by the first parameter of `Debugger::enable()`. You can specify either a constant `Debugger::PRODUCTION` or `Debugger::DEVELOPMENT`.
107115

108-
If it is not specified, the default value `Debugger::DETECT` is used. In this case the system detects a server by IP address. The production mode is choosed if an application is accessed via public IP address. A local IP address leads to development mode. It is not necessary to set the mode in most cases. The mode is correctly recognized when you are launching the application on your local server or in production.
116+
If it is not specified, the default value `Debugger::DETECT` is used. In this case the system detects a server by IP address. The production mode is chosen if an application is accessed via public IP address. A local IP address leads to development mode. It is not necessary to set the mode in most cases. The mode is correctly recognized when you are launching the application on your local server or in production.
109117

110-
In the production mode, Tracy automatically capture all errors and exceptions into a text log. Unless you specify otherwise, it will be a set of log/error.log. This error logging is extremely useful. Imagine, that all users of your application are actually betatesters. They are doing cutting-edge work for free when hunting bugs and you would be silly if you threw away their valuable reports to a recycle bin unnoticed.
118+
In the production mode, Tracy automatically captures all errors and exceptions into a text log. Unless you specify otherwise, it will be stored in log/error.log. This error logging is extremely useful. Imagine, that all users of your application are actually betatesters. They are doing cutting-edge work for free when hunting bugs and you would be silly if you threw away their valuable reports to a recycle bin unnoticed.
111119

112-
If you need a own messages logging or you caught an exception, use the method `log()`:
120+
If you need to log your own messages or caught exceptions, use the method `log()`:
113121

114122
```php
115123
Debugger::log('Unexpected error'); // text message
@@ -119,52 +127,77 @@ try {
119127
} catch (Exception $e) {
120128
Debugger::log($e); // log exception
121129
// or
122-
Debugger::log($e, Debugger::ERROR) // sends also an email notification
130+
Debugger::log($e, Debugger::ERROR) // also sends an email notification
123131
}
124132
```
125133

126-
A directory for errors logging can be set by the second parameter of enable() method:
134+
A directory for errors logging can be set by the second parameter of the enable() method:
127135

128136
```php
129137
Debugger::enable(Debugger::DETECT, __DIR__ . '/mylog');
130138
```
131139

132-
For a real professional is the error log a key source of information and he wants to be noticed about any new error immediately. Tracy helps him. She is capable to send an email on every new error record. The variable $email identify where to send the e-mails:
140+
If you want Tracy to log PHP errors like `E_NOTICE` or `E_WARNING` with detailed information (HTML report), set `Debugger::$logSeverity`:
141+
142+
```php
143+
Debugger::$logSeverity = E_NOTICE | E_WARNING;
144+
```
145+
146+
For a real professional the error log is a crucial source of information and he or she wants to be notified about any new error immediately. Tracy helps him. She is capable of sending an email for every new error record. The variable $email identifies where to send these e-mails:
133147

134148
```php
135149
Debugger::$email = 'admin@example.com';
136150
```
137151

138-
To protect your e-mail box from flood, Tracy sends **the only one message** and creates a file `email-sent`. When developer receives an e-mail notification, he checks the log, corrects application and deletes the monitoring file. It activates the e-mails sending back.
152+
To protect your e-mail box from flood, Tracy sends **only one message** and creates a file `email-sent`. When a developer receives the e-mail notification, he checks the log, corrects his application and deletes the `email-sent` monitoring file. This activates the e-mail sending again.
139153

140154

141-
Variables dumping
155+
Variable dumping
142156
-----------------
143157

144-
Each debugging developer is a good friend with the function `var_dump` which lists a content of a variable in detail. Unfortunately, the output is without HTML formatting and decants dump into a single line of HTML code. Not to mention an context escaping. It is necessary replace the `var_dump` by a handier function. That is just `Debugger::dump()`.
158+
Every debugging developer is a good friend with the function `var_dump`, which lists all contents of any variable in detail. Unfortunately, its output is without HTML formatting and outputs the dump into a single line of HTML code, not to mention context escaping. It is necessary to replace the `var_dump` by a handier function. That is just what `Debugger::dump()` is.
145159

146160
```php
147161
$arr = array(10, 20.2, TRUE, NULL, 'hello');
148162

149-
Debugger::dump($arr);
150-
// including namespace Tracy\Debugger::dump($arr);
163+
dump($arr);
164+
// or Tracy\Debugger::dump($arr);
151165
```
152166

153167
generates the output:
154168

155169
![dump](https://nette.github.io/tracy/images/tracy-dump.png)
156170

157-
You can also change the nesting depth by `Debugger::$maxDepth` and displayed strings length by `Debugger::$maxLen`. Naturally, lower values accelerates Tracy rendering.
171+
You can also change the nesting depth by `Debugger::$maxDepth` and displayed strings length by `Debugger::$maxLen`. Naturally, lower values accelerate Tracy rendering.
158172

159173
```php
160174
Debugger::$maxDepth = 2; // default: 3
161175
Debugger::$maxLen = 50; // default: 150
162176
```
163177

178+
The `dump()` function can display other useful information. `Tracy\Dumper::LOCATION_SOURCE` adds tooltip with path to the file, where the function was called. `Tracy\Dumper::LOCATION_LINK` adds a link to the file. `Tracy\Dumper::LOCATION_CLASS` adds a tooltip to every dumped object containing path to the file, in which the object's class is defined. All these constants can be set in `Debugger::$showLocation` variable before calling the `dump()`. You can set multiple values at once using the `|` operator.
179+
180+
```php
181+
Debugger::$showLocation = Tracy\Dumper::LOCATION_SOURCE; // Shows path to where the dump() was called
182+
Debugger::$showLocation = Tracy\Dumper::LOCATION_CLASS | Tracy\Dumper::LOCATION_LINK; // Shows both paths to the classes and link to where the dump() was called
183+
Debugger::$showLocation = FALSE; // Hides additional location information
184+
Debugger::$showLocation = TRUE; // Shows all additional location information
185+
```
186+
187+
Very handy alternative to `Debugger::dump()` is `Debugger::barDump()`. This allows us to dump variables in Debugger Bar. This is useful, because dumps don't mess up the output and we can also add a title to the dump.
188+
189+
```php
190+
Debugger::barDump([2, 4, 6, 8], 'even numbers up to ten');
191+
Debugger::barDump([1, 3, 5, 7, 9], 'odd numbers up to ten');
192+
```
193+
194+
![bar dump](https://nette.github.io/tracy/images/tracy-bardump.png)
195+
196+
164197
Timing
165198
------
166199

167-
An another useful tool is a debugger stopwatch with a precision of microseconds:
200+
Another useful tool is the debugger stopwatch with a precision of microseconds:
168201

169202
```php
170203
Debugger::timer();
@@ -176,7 +209,7 @@ $elapsed = Debugger::timer();
176209
// $elapsed = 2
177210
```
178211

179-
Multiple measurements can be achieved by an optional parameter.
212+
Multiple measurements at once can be achieved by an optional parameter.
180213

181214
```php
182215
Debugger::timer('page-generating');
@@ -192,32 +225,35 @@ $pageElapsed = Debugger::timer('page-generating');
192225
```php
193226
Debugger::timer(); // runs the timer
194227

195-
... // some difficult operation
228+
... // some time consuming operation
196229

197230
echo Debugger::timer(); // elapsed time in seconds
198231
```
199232

200233

201-
Firebug and FireLogger
202-
----------------------
234+
FireLogger
235+
----------
203236

204-
You cannot send debugging information to the browser window always. This applies to Ajax requests, or generating XML files to output. In such cases, you can send the messages by a separate channel into Firebug. Error, Notice and Warning levels are sent to Firebug window automatically. It is also possible to log suppressed exceptions in running application when attention to them is important.
237+
You cannot always send debugging information to the browser window. This applies to AJAX requests, or generating XML files to output. In such cases, you can send the messages by a separate channel into FireLogger. Error, Notice and Warning levels are sent to FireLogger window automatically. It is also possible to log suppressed exceptions in running application when attention to them is important.
205238

206239
How to do it?
207240

208-
- download and run Firefox browser
209-
- download extension [Firebug](http://getfirebug.com)
210-
- download extension [FireLogger](http://firelogger.binaryage.com)
211-
- restart browser, turn on Firebug (key F12) and enable network (Net) and Logger panels
241+
Firefox:
242+
- install extension [Firebug](http://getfirebug.com/) and [FireLogger](https://addons.mozilla.org/cs/firefox/addon/firelogger/)
243+
- turn on Firebug (using F12 key), enable tabs Net and Logger (stay on Logger)
244+
245+
Chrome:
246+
- install extension [FireLogger for Chrome](https://chrome.google.com/webstore/detail/firelogger-for-chrome/hmagilfopmdjkeomnjpchokglfdfjfeh)
247+
- turn on Chrome DevTools (using Ctrl-Shift-I key) and open Console
212248

213-
... Open our utility panel and click on the Console. Ha!, error message has been moved there.
249+
Navigate to [demo page](https://examples.nette.org/tracy/) and you will see messages sent from PHP.
214250

215-
Because the Tracy\Debugger communicates with Firebug via an HTTP headers, you must call the logging function before the PHP script sends anything to the output. It is also possible to enable the output buffering and delay the output.
251+
Because Tracy\Debugger communicates with FireLogger via HTTP headers, you must call the logging function before the PHP script sends anything to output. It is also possible to enable output buffering and delay the output.
216252

217253
```php
218254
use Tracy\Debugger;
219255

220-
Debugger::fireLog('Hello World'); // render string into Firebug console
256+
Debugger::fireLog('Hello World'); // send string into FireLogger console
221257

222258
Debugger::fireLog($_SERVER); // or even arrays and objects
223259

@@ -226,4 +262,4 @@ Debugger::fireLog(new Exception('Test Exception')); // or exceptions
226262

227263
The result looks like this:
228264

229-
![FireLogger](https://nette.github.io/tracy/images/firelogger.png)
265+
![FireLogger](https://nette.github.io/tracy/images/tracy-firelogger.png)

0 commit comments

Comments
 (0)