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

pyln: Add logging handler that passes records to lightningd #4101

Merged
merged 1 commit into from Oct 13, 2020

Conversation

cdecker
Copy link
Member

@cdecker cdecker commented Sep 29, 2020

It is often pretty usefuk to use the builtin logging module to debug things,
including libraries that a plugin may use. This adds a simple
PluginLogHandler that maps the python logging levels to the lightningd
logging levels, and formats the record in a way that it doesn't clutter up the
lightningd logs (no duplicate timestamps and levels).

This allow us to tweak the log level that is reported to lightningd simply
using the following

import logging
logging.basicConfig(level=logging.DEBUG)

Notice that in order for the logs to be displayed on the terminal or the
logfile, both the logging level in the plugin and the --log-level
lightningd is running need to be adjusted (the python logging level only
controls which messages get forwarded to lightningd, it does not have the
power to overrule lightningd about what to actually display).

I chose logging.INFO as the default, since libraries have a tendency to spew
out everything in logging.DEBUG mode

Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Ack a3e18be

It is often pretty usefuk to use the builtin logging module to debug things,
including libraries that a plugin may use. This adds a simple
`PluginLogHandler` that maps the python logging levels to the `lightningd`
logging levels, and formats the record in a way that it doesn't clutter up the
`lightningd` logs (no duplicate timestamps and levels).

This allow us to tweak the log level that is reported to `lightningd` simply
using the following

```python3
import logging
logging.basicConfig(level=logging.DEBUG)
```

Notice that in order for the logs to be displayed on the terminal or the
logfile, both the logging level in the plugin _and_ the `--log-level`
`lightningd` is running need to be adjusted (the python logging level only
controls which messages get forwarded to `lightningd`, it does not have the
power to overrule `lightningd` about what to actually display).

I chose `logging.INFO` as the default, since libraries have a tendency to spew
out everything in `logging.DEBUG` mode

Changelog-Added: pyln: Plugins have been integrated with the `logging` module for easier debugging and error reporting.
@cdecker cdecker merged commit 556725c into ElementsProject:master Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants