Logging
The logger is automatically mixed into all driver classes and has the usual logger levels:
    debug: use debug often for verbose output - not saved to log files by default
    info: anything you are interested in seeing in the log file
    warn: something might be wrong, possibly worth investigation.
    error: something went wrong, definitely worth investigation
    fatal: something that should never go wrong, went wrong. Requires immediate investigation / resolution
If text being passed to the logger requires some string manipulation or other processor intensive operation, it is worth performing this work in a block in case the result is not recorded - this is preferred with debug statements as they are discarded when nobody is watching.
1
def received(data, resolve, command)
2
logger.debug {
3
cmd = String.new("Device sent 0x#{byte_to_hex(data)}")
4
cmd << " for command #{command[:name]}" if command
5
cmd # return the text to be displayed if we are debugging
6
}
7
end
Copied!
There is also a handy helper method for formatting errors:
1
begin
2
raise 'whoa!'
3
rescue => e
4
logger.print_error e, 'optional additional description of error'
5
end
Copied!
Last modified 2yr ago
Copy link