I am running Raspian Stretch on a Pi3 with systemd starting homebridge on boot. What do I enter for the log files location in the config?
I tried:
log: "systemd"
log: "var/log/daemon.log"
log: "/var/log/homebridge.log"
It would be nice to use the Log Screen.
The log should point to the log file specified in your system.d homebridge.service. If you're not logging to a file in your homebridge.service you'll need to configure that first.
I might play around and see if I can add an option to get the logs from from journald/syslog.
Getting the logs from journald or syslog would be helpful.
This was a pretty simple task when using web sockets. See https://github.com/oznu/homebridge-config-ui-x#log-viewer-configuration.
"platform":[
{
"platform": "config",
"name": "Config",
"port": 8080,
"restart": "systemctl restart homebridge",
"log": {
"tail": "journalctl -o cat -n 100 -f -u homebridge"
}
}
]
The -o cat flag removes the journalctl timestamps, Homebridge is already adding these so there is no need for duplicates. The -n 100 flag gets displays the last 100 lines of the log then -f outputs any new lines.
If you're not running Homebridge as root you will need to grant the user which is permissions to access journalctl OR prepend the tail command with sudo and allow the user passwordless sudo access. Both of these are things you'll need to Google yourself though 😄 .
I copied and pasted your new config for the log into my config.json. I double checked that my user for homebridge which is named homebridge had access.
sudo usermod -a -G systemd-journal homebridge
I use another plugin named "server" that is able to show me the log file in a browser. I do not know why I am unable to see the log in the browser still.
What are you using for "log" so the log is shown as in your screenshot?
The homebridge-server plugin works by calling journalctl as well. They don't use websockets to stream the log though. https://github.com/gismo141/homebridge-server/blob/master/index.js#L473
Does anything show up on the log page at all? If not, it's the WebSocket not working and not a config problem. What browser are you using?
I tried Safari on my iPhone and it worked. Yay!! So I went back to my Mac running Firefox and tried to view the logs there. It did not work. So I disabled my adblocker and its working now.
You may want to mention that if the logs don't show up to try a different browser or to disable ad blockers.
Thanks you for your help and quick responses!! I really like your plugin and was very excited to use all of the features. I was disappointed that I was not able to view the logs but now all is well.
Thanks again and happy new year to you!!
Glad to hear you got it working and thanks for figuring out the Ad Blocker issue. I'll add that to the README and adjust the code so an error shows up in the ui if the websocket connection errors rather than just silently failing.
Im using systemd to start homebridge and using the suggested
"log": {
"tail": "journalctl -o cat -n 100 -f -u homebridge"
}
to get logs but I'm shown this message:
No journal files were opened due to insufficient permissions.
The log tail command "journalctl -o cat -n 100 -f -u homebridge" exited unexpectedly with code 1. Please check the command in your config.json is correct.
How does one correct this?
@halpls the message you are shown tells us the problem:
No journal files were opened due to insufficient permissions.
As mentioned earlier:
If you're not running Homebridge as root you will need to grant the user which is permissions to access journalctl OR prepend the tail command with sudo and allow the user passwordless sudo access. Both of these are things you'll need to Google yourself though.
Run: sudo visudo
Under: # User privilege specification
Add: homebridge ALL = NOPASSWD: ALL
Now works.
I'm having a slightly different issue with the log file functions. It will display the log, but it can take upwards of 3-4 minutes to actually post the information. During this time, the plugin is unresponsive (can't go to other tabs) and completely locks up the Homebridge service (all accessories show No Response).
It will respond if you let it be long enough, but it is a bit of a pain if you are looking to view the logs. Viewing them nativly via the command line on the Pi causes no similar issues.
@ansuz07 what method are you using to load the log files in the config.json? File path or tail command?
tail command. Tried both, though - same issues.
It sounds like you are accessing the UI in a browser also running on the Raspberry Pi? Is this correct? If so can you try accessing it from a browser on another computer instead and see if that works so I can determine if the problem is with the client side or server side code.
Just tried it on Edge, Chrome and Firefox. For Edge and Chrome, it gave the behavior I reported. On Firefox, it caused an error that crashed homebridge:
event.js:183 - throw er; // Unhandled 'error' event
Error: kill EPERM
at _errnoException (util.js:1024:11)
at ChildProcess.kill (internal/child_process.js:395:26)
at WebSocket.ws.on (/usr/lib/node_modules/homebridge-config-ui-x/lib/wss-logs.js:62:10)
at emitTwo (events.js:131:20)
at WebSocket.emit (events.js:214:7)
at WebSocket.emitClose (/usr/lib/node_modules/homebridge-config-ui-x/node_modules/ws/lib/WebSocket.js:211:10)
at _receiver.cleanup (/usr/lib/node_modules/homebridge-config-ui-x/node_modules/ws/lib/WebSocket.js:199:39)
at Receiver.cleanup (/usr/lib/node_modules/homebridge-config-ui-x/node_modules/ws/lib/Receiver.js:520:15)
at WebSocket.finalize (/usr/lib/node_modules/homebridge-config-ui-x/node_modules/ws/lib/WebSocket.js:199:20)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1056:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
And yes, I'm running on a PI accessing via a browser on my network.
Thanks. I'll try and replicate on a Pi later on. What model are you using?
Normal PI3 running OS version 4.9.59-v7 on the latest release of both Homebridge and Config UI X
Really appreciate the help.
@ansuz07 I have loaded this up on a Raspberry Pi 3:
root@raspberrypi:/home/pi# cat /etc/*release*
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
root@raspberrypi:/home/pi# uname -a
Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux
root@raspberrypi:/home/pi# node -v
v8.9.4
root@raspberrypi:/home/pi# homebridge -V
0.4.33
root@raspberrypi:/home/pi# npm -g list | grep homebridge-config-ui-x
├─┬ [email protected]
I have tested this in two ways:
Start Command:
homebridge -U /var/lib/homebridge > /var/log/homebridge.log
Config:
{
"bridge": {
"name": "Homebridge",
"username": "CC:22:3D:E3:CE:30",
"port": 51826,
"pin": "031-45-154"
},
"description": "",
"accessories": [],
"platforms": [
{
"platform": "config",
"name": "Config",
"port": 8080,
"log": "/var/log/homebridge.log"
}
]
}
Start Command:
systemctl start homebridge
How to setup homebridge using systemd - I'm running it as root.
Config:
{
"bridge": {
"name": "Homebridge",
"username": "CC:22:3D:E3:CE:30",
"port": 51826,
"pin": "031-45-154"
},
"description": "",
"accessories": [],
"platforms": [
{
"platform": "config",
"name": "Config",
"port": 8080,
"restart": "systemctl restart homebridge",
"log": {
"tail": "journalctl -o cat -n 100 -f -u homebridge"
}
}
]
}
Both these setups work for me and I can view the logs without issue in Chrome, Firefox and Safari on macOS.
Thanks for looking into it. It must be a problem on my end. I’ll play around with it.
Hey - just to follow up, the issue was on my end entirely.
Logging option documentation updated to include all possible methods:
https://github.com/oznu/homebridge-config-ui-x#log-viewer-configuration
@oznu
I'm using PM2 (Start on Boot) would it be the same setup?
{
"bridge": {
"name": "Home8",
"username": "",
"port": 51828,
"pin": "031-45-158"
},
"platforms": [
{
"platform": "config",
"name": "Config",
"port": 8087,
"log": {
"log": "/var/log/homebridge.log"
}
},
{
to follow up, a little research I found out that PM2 is using Systemd so I copied the steps as below but keep getting an error
"restart": "sudo -n systemctl restart homebridge",
"log": {
"method": "systemd",
"service": "homebridge"
Error
Cannot show logs. "log" option is not configured correctly in your Homebridge config.json file.
See https://github.com/oznu/homebridge-config-ui-x#log-viewer-configuration for instructions.
to follow up, a little research I found out that PM2 is using Systemd so I copied the steps as below but keep getting an error
"restart": "sudo -n systemctl restart homebridge", "log": { "method": "systemd", "service": "homebridge"Error
Cannot show logs. "log" option is not configured correctly in your Homebridge config.json file.See https://github.com/oznu/homebridge-config-ui-x#log-viewer-configuration for instructions.
for pm2 you can simply add this to the config to see the logs
"log": {
"method": "file",
"path": "/.pm2/logs/homebridge-out.log"
}
to follow up, a little research I found out that PM2 is using Systemd so I copied the steps as below but keep getting an error
"restart": "sudo -n systemctl restart homebridge", "log": { "method": "systemd", "service": "homebridge"Error
Cannot show logs. "log" option is not configured correctly in your Homebridge config.json file.
See https://github.com/oznu/homebridge-config-ui-x#log-viewer-configuration for instructions.
MORE PM 2 LINKSfor pm2 you can simply add this to the config to see the logs
"log": {
"method": "file",
"path": "/.pm2/logs/homebridge-out.log"
}
I've tried this and I get the following error:
Loading logs using "file" method...
CMD: sudo -n tail -n 500 -f /.pm2/logs/homebridge-out.log
tail: cannot open '/.pm2/logs/homebridge-out.log' for reading: No such file or directory
tail: no files remaining
The log tail command "-n tail -n 500 -f /.pm2/logs/homebridge-out.log" exited with code [object Object].
Please check the command in your config.json is correct.
See https://github.com/oznu/homebridge-config-ui-x#log-viewer-configuration for instructions.
you have to check the correct path for the .pm2
you have to check the correct path for the .pm2
Sorry, I'm pretty new to all of this. How do I find the correct path?
you have to check the correct path for the .pm2
Sorry, I'm pretty new to all of this. How do I find the correct path?
Sorry, here you go, try with readlink
readlink -f homebridge-out-log
Just posting this here, since it wasn't obvious to me, but I figured out how to do it.
This is for people that don't use services, but start homebridge manually:
./homebridge -I > ~/.homebridge/homebridge.log
And then in your config.json file:
{
"platform": "config",
"name": "Config",
"port": 8082,
"sudo": false,
"log": {
"method": "file",
"path": "/home/{USERNAME}/.homebridge/homebridge.log"
}
}
Replace {USERNAME} with your username, or simply replace the path with whatever you plan to use as the path when starting homebridge.