Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced debugging features: #870

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/sonos-http-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,27 @@ function HttpAPI(discovery, settings) {
}

const params = req.url.substring(1).split('/');


// Change node environment log level on request.
if (/^\/loglevel\/.+$/.test(req.url)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified with req.url.startsWith('/loglevel/'), no need for a regexp.

let param = params[1];
switch (param) {
case 'off':
param = 'error';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I don't follow what off would actually set. I would also like that just getting /loglevel would actually return the current loglevel.

case 'trace':
case 'debug':
case 'info':
case 'warn':
case 'error':
process.env.NODE_LOG_LEVEL = params[1];
sendResponse(200, { loglevel: param });
break;
default:
sendResponse(500, { error: `${param} is not a log level` });
}
return;
}

// parse decode player name considering decode errors
let player;
try {
Expand Down
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const discovery = new SonosSystem(settings);
const api = new SonosHttpAPI(discovery, settings);

var requestHandler = function (req, res) {
req.addListener('end', function () {
logger.debug(`request: ${req.url}`);
req.addListener('end', function () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation, it's two spaces.

fileServer.serve(req, res, function (err) {

// If error, route it.
Expand Down
1 change: 1 addition & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ <h2>Global Control</h2>
<p><span class="method">GET</span> /sleep/{timeout in seconds or timestamp HH:MM:SS or off}</p>
<p><span class="method">GET</span> /preset/{JSON preset}</p>
<p><span class="method">GET</span> /preset/{predefined preset name}</p>
<p><span class="method">GET</span> /loglevel/{trace|debug|info|warn|error|off}}</p>
</div>

<div class="docs">
Expand Down