2017-10-10 11:15:24 +02:00
# Logging
Strapi relies on an extremely fast Node.js logger called Pino that includes a shell utility to pretty-print its log files. It provides great performances and doesn't slow down your app. The logger is accessible through the global variable `strapi.log` or the request's context `ctx.log` if enabled.
```js
// Folder.js controller
const fs = require('fs');
const path = require('path');
module.exports = {
/**
* Retrieve app's folders.
*
* @return {Object|Array}
*/
findFolders: async (ctx) => {
try {
const folders = fs.readdirSync(path.resolve(process.cwd()));
strapi.log.info(folders); // ctx.log.info(folders);
ctx.send(folders);
2017-10-11 10:51:28 +02:00
} catch (error) {
2017-10-10 11:15:24 +02:00
strapi.log.fatal(error); // ctx.log.fatal(error);
2017-10-11 10:51:28 +02:00
ctx.badImplementation(error.message);
}
2017-10-10 11:15:24 +02:00
}
}
```
2018-03-01 13:36:54 +01:00
## Global logger configuration
2017-10-10 11:15:24 +02:00
2018-03-01 13:36:54 +01:00
The global logger is configured by environment variables.
2018-03-01 13:44:25 +01:00
`STRAPI_LOG_LEVEL` : Can be 'fatal', 'error', 'warn', 'info', 'debug' or 'trace'.
2018-03-01 13:36:54 +01:00
`STRAPI_LOG_TIMESTAMP` : Can be true/false
`STRAPI_LOG_PRETTY_PRINT` : Can be true/false
`STRAPI_LOG_FORCE_COLOR` : Can be true/false
## Request logging middleware
To configure the request-logger middleware, you have to edit the following file `./config/environments/*/request.json` .
2017-10-10 11:15:24 +02:00
```json
{
...
"logger": {
"level": "debug",
"exposeInContext": true,
"requests": true
},
...
}
```
- `level` : defines the desired logging level (fatal, error, warn, info, debug, trace).
- `exposeInContext` : allows access to the logger through the context.
- `requests` : incoming HTTP requests will be logged.
To find more details about the logger API, please refer to the [Pino documentation ](http://getpino.io/#/ ).