Roon API: log levels

We got tired of the API library constantly printing ping messages to the console as well. So, I just finished implementing user selectable logging levels for the node.js API library. By default the library know prints all requests from the library to the Roon core, and all requests and responses from the Roon core to the library that don’t have a “Logging: quiet” header set. This is basically everything except the ping messages right now, and is the behavior you will get if you just update the library and do nothing else.

Extensions can also ask for printing of every message or no messages by setting a ‘log_level’ option in the options object passed to the RoonApi constructor. Set “all” for every message, and “none” for no messages. Here’s an example, taken from the github readme for the library:
var RoonApi = require(“node-roon-api”);

var roon = new RoonApi({
    extension_id:        'com.elvis.test',
    display_name:        "Elvis's First Roon API Test",
    display_version:     "1.0.0",
    publisher:           'Elvis Presley',
    email:               'elvis@presley.com',
    website:             'https://github.com/elvispresley/roon-extension-test',
    log_level:           'none'
});

roon.init_services({});

roon.start_discovery();

Hopefully that explanation made sense, let me know if you have any questions.

The log level should update in real time, so it’s possible to write an extension such that the amount of logging is configurable as a setting after the extension is running. I’m not sure this is actually useful, but it seemed like it might be so I did it.

It’s possible we’ll add more complex behavior here in the future, but this seems like a good start. As always, please let us know here or in a github issue if you find any bugs with the library. We’ll do our best to fix things, we need to use this library internally as well.

6 Likes

Thanks @ben! This is much cleaner than what I was doing - commenting out the console.log lines in the API…