This is a simple module to demonstrate Viam logging capabilities.
A simple sensor component which logs "debug", "info", "warning" and "error" messages upon calling the Readings() API.
This module/component doesn't require any configuration. However for simplicity reasons you may want to leverage this fragment which provides a ready made demo setup.
Viam Server has a variety of interesting settings for debugging which you can set directly when starting the service. Two options you will likely find useful:
-log-file <file name>Write logs to a file with log rotation-debugOutputs debug log messages and also sends them to app.viam.com
Besides directly adding debug logging through the Viam Server binary, further options are available through the machine configuration.
Machine level log settings will overwrite subsettings.
- Add
"debug":trueto the top level of your machine JSON configuration. This is analog adding the Viam server startup parameter. No Viam server restart required. - For more granularity you can use the top level "log" element:
"log": [ { "pattern": "rdk.services.*", // TODO: Haven't properly understood the behavior yet "level": "debug" }, { "pattern": "<module name>", // Works fine "level": "debug" } ]
To enable debug logs for a whole module you can add the following to your module JSON configuration:
"log_level": "debug"To enable debug log level for a single component you can either enable it via context menue or add this to the component JSON config. Module / component restart required
"log_configuration":{
"level": "debug"
}Viam-server deduplicates log message that are deemed noisy. A log is deemed noisy if it has been output 3 times in the past 10 seconds. As this can complicate debugging issues, you can disable it as follows.
Add the following line to the root level in the machine config:
"disable_log_deduplication": trueThis is handled by the Viam agent and can be enable with the following sample configuration:
"agent": {
"system_configuration": {
"forward_system_logs": "kernel,NetworkManager,tailscaled"
}
}You can test this functionality by adding the username to the above filter string and then log messages from a shell as follows:
logger -p user.warning "My message!"With the DoCommand() you can trigger log entries at different levels.
Example DoCommand:
{
"message": "info" // one of [debug, info, warn, error or fatal]
}git tag x.x.x
git push origin --tag x.x.x