Logging
In this section, you will learn how to log certain data in your Jovo app.
Introduction to Logging
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:
Basic Logging
You can enable logging by using the following:
This will enable both Request Logging and Response Logging, which can also be enabled separately. For this, see the sections below.
Log Requests
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:
Log Responses
You can log the outgoing JSON responses by adding the following configuration:
The result looks like this:
Similar to requestLoggingObjects
, you can limit the response logging output to specific objects, as well.
The example above will reduce the log output to this:
Jovo Logger
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.
Log Levels
You can set the log level by adding an environment variable, for example in your app.js
file:
The following log levels are supported:
ERROR
: Only display errorsWARN
: Display warnings and errorsINFO
: Display infos, warnings, and errors (default
)VERBOSE
: Display additional information, e.g. when certain middlewares are executedDEBUG
: Display all information, even configs that might include sensitive data (like API keys). Only recommended to use while debugging
Using the Jovo Logger in your App
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:
Log.error
Log.info
Log.warn
Log.verbose
Log.debug
Formatting
You can also use helpers to format the log output, like this:
The following methods are available:
- Font colors
black()
red()
green()
yellow()
blue()
magenta()
cyan()
white()
- Background colors
blackBackground()
redBackground()
greenBackground()
yellowBackground()
magentaBackground()
cyanBackground()
whiteBackground()
- Other formatting
underscore()
bold()
dim()
blink()
reverse()
Appenders
You can also define log appenders. For example, the below code imports the Log
and 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 ERROR
):
Logging Helpers
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:
The dd
is short for "dump and die," which means that the execution ends after this log. This helper is inspired by Laravel's dd()
.