# 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.&#x20;

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.&#x20;

### 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](https://tracy.nette.org/en/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);
```

&#x20;To reduce the amount of logged messages, specify a minimum level to be logged:

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://andygrond.gitbook.io/hugonette/basic-usage/general-tools.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
