Logs?

Is there a place that I can get the logs other than having a browser open to the logs tab?

1 Like

Don’t think so.

Device events, hub events, and location events are all available after the fact on their respective pages. What you would be missing are debug/info logs that are only available in the Logs page when it is open.

1 Like

It would be nice to have a text file or something we can open with excel to sort through.

1 Like

Sending to an external syslog server would be nice.

7 Likes

Bumping this thread. I've submitted a couple of tickets for what seems to be some problems with .121. Having a browser opened to the log page on a separate machine really helped with the ticket submission. It would be an incredible help to those of us wanting to improve HE to have some way to setup a syslog server. The browser-on-another-machine is an okay workaround, but if a variety of things happen, all that data is lost.

1 Like

how about a simple nodejs app that connects to the websocket and logs out the messages? then pipe that to a file to troll through later.

1 Like

Something to start with.. change ip address to your hub ip

const WebSocket = require('ws');

const ws = new WebSocket('ws://192.168.1.172/logsocket');

ws.on('open', function open() {
   // do nothing
});

ws.on('message', function incoming(data) {
  console.log(data);
});

running:

example command to save output to file:
nodejs logCaptureExample.js > hubLogs.txt

2 Likes

I've noticed that while the logs are showing, the system doesn't run as fast as when they are not when a lot of logs are coming through. Are the logs pushed synchronously to the browser from the app and device drivers? If so can they be updated to be pushed asynchronously in the future. I've held off on a constant connection for exporting my logs for this reason.

Thanks for pointing that out. It is synchronous, I'll create an issue to update it to async.

5 Likes

Thank you very much. I installed node.js on my Mac and then setup a log rotation for the files. This is great!

I've integrated this with a sumo logic collector - with a free tier license; and it works great; it's allowing me to clean up custom apps and device handlers in a way that I've never been able to do before in 5 yrs of ST use.

Was this updated to async or does it still have the performance impact downside?

See the changelog here

1 Like

Minollo,

Can you share what you are doing? I have installed the npm sumo logic code, modified @chuck.schwer code to the following:

const WebSocket = require('ws');
const SumoLogger = require('sumo-logger');

const opts = {
      endpoint: '<my sumo end_point>'
};
const ws = new WebSocket('ws://<my HE IP>/logsocket');

const sumoLogger = new SumoLogger(opts);

ws.on('open', function open() {
   // do nothing
});

ws.on('message', function incoming(data) {
  console.log(data);
  sumoLogger.log(data);
});

I see the logs on the Pi console and I see Sumo Logic is receiving the logs but I have no idea how to get Sumo to parse and commit logs into its data repository. Any insight is appreciated!

If data is reaching sumologic, then you should be in good shape. For example, you can create a new log search in sumologic with a query like:
_sourceCategory="hubitat" | json auto | where level = "error" or level = "warn"
(replace the _sourceCategory value with what you used to register your sumo end point)
That will return - in whatever time interval you choose - all the error/warning level log entries. You'll want to choose which fields to display/hide; typically I display only Time, level, msg and name.

1 Like

Any luck on getting this to work long-term? It works for a few minutes then it stops. Was thinking about wrapping node logger.js in a shell script while loop, but wasn’t sure if there was a better option.

pm2 or forever will run nodejs scripts as processes.

pm2 is my preference, but forever pretty much does the same thing.

You can install either via npm.

npm install pm2
npm install forever

1 Like

Hmm, looked through the WS codebase and did not find 'logoscket' - this something internal to Hubitat?
:slight_smile: