anthonywebb / homebridge-cbus

CBus plugin for homebridge
MIT License
35 stars 20 forks source link

Reinstate logging switch #18

Closed simonhac closed 7 years ago

simonhac commented 7 years ago

i carelessly removed the debugging switch when i was working on #16.

i'd like to keep the option of richer logging but allow users a level of control over the verbosity.

for unit tests i've started to use the debug library (32.5M downloads over last month), but looks like homebridge uses its own internal debug library. should we stick with that?

simonhac commented 7 years ago

@anthonywebb i'm a little stuck here -- looking for advice.

homebridge uses its own internal logging class -- homebridge/lib/logger.js. homebridge is built on top of hap-nodejs which uses the very popular and more sophisticated debug module.

which is why we see HAP messages in the one format and homebridge-* messages in another.

i prefer the debug module -- supports quick enable/disable from environment variables and has (i think) prettier output. i think it would have been much nicer if homebridge used debug, but i'm not going to try to turn that ship around, yet.

i'd like to have different log streams:

  1. raw C-Gate event traffic
  2. interesting C-Gate events (in plain english)
  3. cgate-client and cgate-database major events -- (re)opening sockets, loading database, etc.
  4. platform logging
  5. accessory logging

it'd be pain to hack homebridge's logger to enable multiple streams.

what do you think if i use debug for the first three streams above?

i'm happy to leave accessory and platform logging as they were -- using logger.js -- for consistency with other homebridge plugins if we think that's useful/good manners. (but just as happy to move homebridge-cbus fully across to debug so we have only one way of configuring the loggers...)

keen to hear your opinion...

anthonywebb commented 7 years ago

I'm perfectly find for enhanced logging, it should be noted in the readme though with how it works so that it isnt a mystery that only the owner can decipher. How do you intend to identify the various log streams? Color I assume?

simonhac commented 7 years ago

addressed in PR #20.

added to README.md:

Logging

homebridge-cbus has four logging channels:

On startup, the status of the channels will be determined from the environment variable DEBUG. eg.:

# all C-Bus logging
> DEBUG=cbus:* homebridge

# just level change events
> DEBUG=cbus:level homebridge

# very verbose logging from all of homebridge
> DEBUG=* homebridge 

N.B. If provided, the client_debug setting (from config.json) will override the configuration for cbus:client from the environment.

Example logging output

image

simonhac commented 7 years ago

addressed with PR #20.