General tools

You get several simple features, which can be used anywhere in the program.

Env

use Andygrond\Hugonette\Env;

Env static class is a container for environment variables. Some of variables are preset by router. You can use Env to set more according to your needs.

Variables are stored in an array, but the access methods use convenient object-like notation:

Env::get('request.segments.1');
Env::get();    // full Env array
Env::set('user.login', $login);

You can also concatenate strings and push an element to the end of an array:

Env::prepend($prepended_string, 'existing.string');
Env::append('existing.string', $appended_string);
Env::push('array', $new_element);

Env is initiated in Bootstrap, where you should declare an app mode:

Env::set('mode', 'development');

When you aren't in production mode and you use Tracy, all your Env variables are visible in the bottom-right Tracy bar.

Tracy

Enable Tracy to use awesome debugging features of Nette Framework.

Log::enable('tracy');

You can use Nette Dumper in any place to see your data for debugging:

dump()     - var_dump with formatting
dumpe()    - dump and exit
bdump()    - dump in Tracy bar

You can also configure your Tracy bar, see Tracy guide.

Log

use Andygrond\Hugonette\Log;

Log static class provides simple logging features, like always PSR-3 compatible. So you can log with levels: emergency, alert, critical, error, warning, notice, info, debug. Provide a text message and optionally a context, which is any data structure.

Log::warning($message, $context);

Log gives you one more level view to register messages, which are relevant to the user. View messages are stored in an array Log::$viewMessages

You can measure a performance of certain fragments of your code, defining jobs. Find results in the log file.

Log::job('job-name');
...
Log::done('job-name');

Log must be set before the first use, to inject a logger. It is done usually at the beginning of routes.php:

Log::set(new Logger('myblog.log', 3));

You must pass to the new logger a log file name. Set a file size in Mb, on which log files will be shifted.

If you want to log any part of your app in a separate log file, use Logger independently. At the 3-rd argument you can set max number of archived files.

$this->log = new Logger('myprocess.log', 3, 10);

To reduce the amount of logged messages, specify a minimum level to be logged:

$this->log->minLevel('info');

Last updated