In this section, you will learn how to log certain data in your Jovo app.
- Basic Logging
- Jovo Logger
- Logging Helpers
When you're using a local webhook, it's easy to use logging for debugging, like this:
For voice app specific debugging, Jovo offers some handy functions for logging incoming requests and outgoing responses:
You can enable logging by using the following:
You can log the incoming JSON requests by adding the following configuration:
The result looks like this (data changed):
As you can see above, the logs of a request are quite long and impractical, if you only need certain information. With
requestObjects, you can limit the log output to specific objects.
The example for
request above will reduce the log output to this:
You can log the outgoing JSON responses by adding the following configuration:
The result looks like this:
requestLoggingObjects, you can limit the response logging output to specific objects, as well.
The example above will reduce the log output to this:
Find the source code of the Jovo Logger here: jovo-core/Log.
Jovo has an internal logging class that can be used to display certain levels of logs.
You can set the log level by adding an environment variable, for example in your
The following log levels are supported:
ERROR: Only display errors
WARN: Display warnings and errors
INFO: Display infos, warnings, and errors (
VERBOSE: Display additional information, e.g. when certain middlewares are executed
DEBUG: Display all information, even configs that might include sensitive data (like API keys). Only recommended to use while debugging
You can use the Jovo
Log class in your app logic to log certain things for different levels.
First, import the class into your project:
You can then use it in your app logic to log things for different levels:
You can use the following log levels for this:
You can also use helpers to format the log output, like this:
The following methods are available:
- Font colors
- Background colors
- Other formatting
You can also define log appenders. For example, the below code imports the
LogLevel classes and then adds a file appender (save logs to a file with a specified name, in this case
errors.log) for a certain log level (in this case
If you find yourself searching for that one log that is buried somewhere in all the request and response logs, you can use the following helper method:
dd is short for "dump and die," which means that the execution ends after this log. This helper is inspired by Laravel's