-
Notifications
You must be signed in to change notification settings - Fork 85
Description
Problem
At the moment, there is no device-level filtering or setting of logging levels. This means that when the log level for an Essentials program is set to VERBOSE, there is a flood of information in the console, making it difficult to see messages that might give an indication of problems or how the system is working.
Essentials uses Serilog for logging. Serilog is configurable, and has multiple built-in mechanisms for overriding the allowed log level, usually based on the C# type. Essentials could use that mechanism, but there are limitations to that sort of mechanism, as all instances of a type would be set to the log at the same level.
Suggested Fixes
As long as plugins/devices use the logging extensions, or the overloads of the various Debug logging methods that take an IKeyed as a parameter, all log messages are enriched with a Key property. This Key property can be used to determine a log level based on Key, with the log level only applied to statements from devices with that key.
Add a console command devdebug
This console command will take 2 arguments: devdebug {keyPattern} {level}
The keyPattern could be a complete key or a valid regex that would match a set of keys, allowing for setting all displays or all nvx endpoints to the same level.
The level will be a valid Serilog level
There should be 2 special values for the keyPattern: all will set all devices to the same log level, while clear will reset all devices to the level set for the console sink using the appdebug command
Filtering
When the devdebug command is issued, all device keys that match the pattern will be retrieved from the device manager, then each key will be added to a dictionary maintained in the debug class, with the key being the device key and the value being the log level for that key.
Then, the logging configuration needs to be modified to use a sublogger for the console sink, with a filter added to check if a log event has the Key property AND the Key Property is in the dictionary AND the level for the event is greater than the level from the dictionary. If the Key ISN'T in the dictionary at all, then the message will proceed through the pipeline. If there isn't a Key property at all, the message will proceed through the pipeline.
Messages for the console would still be subject to the main setting using the appdebug command. If a device with the key display1 is set to log at Verbose using the devdebug command, but the console sink is set to Information, then the Verbose messages from display1 would still not be seen.