You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
579 B

#ifndef LIGHTNING_LIGHTNINGD_NOTIFICATION_H
#define LIGHTNING_LIGHTNINGD_NOTIFICATION_H
#include "config.h"
#include <lightningd/jsonrpc.h>
#include <lightningd/lightningd.h>
plugin: Add new notification type: warning This notification bases on `LOG_BROKEN` and `LOG_UNUSUAL` level log. --Introduction A notification for topic `warning` is sent every time a new `BROKEN`/ `UNUSUAL` level(in plugins, we use `error`/`warn`) log generated, which means an unusual/borken thing happens, such as channel failed, message resolving failed... ```json { &#34;warning&#34;: { &#34;level&#34;: &#34;warn&#34;, &#34;time&#34;: &#34;1559743608.565342521&#34;, &#34;source&#34;: &#34;lightningd(17652): 0821f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #7854:&#34;, &#34;log&#34;: &#34;Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR bad reestablish dataloss msg&#34; } } ``` 1. `level` is `warn` or `error`: `warn` means something seems bad happened and it&#39;s under control, but we&#39;d better check it; `error` means something extremely bad is out of control, and it may lead to crash; 2. `time` is the second since epoch; 3. `source`, in fact, is the `prefix` of the log_entry. It means where the event happened, it may have the following forms: `&lt;node_id&gt; chan #&lt;db_id_of_channel&gt;:`, `lightningd(&lt;lightningd_pid&gt;):`, `plugin-&lt;plugin_name&gt;:`, `&lt;daemon_name&gt;(&lt;daemon_pid&gt;):`, `jsonrpc:`, `jcon fd &lt;error_fd_to_jsonrpc&gt;:`, `plugin-manager`; 4. `log` is the context of the original log entry. --Note: 1. The main code uses `UNUSUAL`/`BROKEN`, and plugin module uses `warn` /`error`, considering the consistency with plugin, warning choose `warn` /`error`. But users who use c-lightning with plugins may want to `getlog` with specified level when receive warning. It&#39;s the duty for plugin dev to turn `warn`/`error` into `UNUSUAL`/`BROKEN` and present it to the users, or pass it directly to `getlog`; 2. About time, `json_log()` in `log` module uses the Relative Time, from the time when `log_book` inited to the time when this event happend. But I consider the `UNUSUAL`/`BROKEN` event is rare, and it is very likely to happen after running for a long time, so for users, they will pay more attention to Absolute Time. -- Related Change 1. Remove the definitions of `log`, `log_book`, `log_entry` from `log.c` to `log.h`, then they can be used in warning declaration and definition. 2. Remove `void json_add_time(struct json_stream *result, const char *fieldname, struct timespec ts)` from `log.c` to `json.c`, and add related declaration in `json.h`. Now the notification function in `notification.c` can call it. 2. Add a pointer to `struct lightningd` in `struct log_book`. This may affect the independence of the `log` module, but storing a pointer to `ld` is more direct;
5 years ago
#include <lightningd/log.h>
#include <lightningd/plugin.h>
bool notifications_have_topic(const char *topic);
void notify_connect(struct lightningd *ld, struct node_id *nodeid,
struct wireaddr_internal *addr);
void notify_disconnect(struct lightningd *ld, struct node_id *nodeid);
plugin: Add new notification type: warning This notification bases on `LOG_BROKEN` and `LOG_UNUSUAL` level log. --Introduction A notification for topic `warning` is sent every time a new `BROKEN`/ `UNUSUAL` level(in plugins, we use `error`/`warn`) log generated, which means an unusual/borken thing happens, such as channel failed, message resolving failed... ```json { &#34;warning&#34;: { &#34;level&#34;: &#34;warn&#34;, &#34;time&#34;: &#34;1559743608.565342521&#34;, &#34;source&#34;: &#34;lightningd(17652): 0821f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #7854:&#34;, &#34;log&#34;: &#34;Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR bad reestablish dataloss msg&#34; } } ``` 1. `level` is `warn` or `error`: `warn` means something seems bad happened and it&#39;s under control, but we&#39;d better check it; `error` means something extremely bad is out of control, and it may lead to crash; 2. `time` is the second since epoch; 3. `source`, in fact, is the `prefix` of the log_entry. It means where the event happened, it may have the following forms: `&lt;node_id&gt; chan #&lt;db_id_of_channel&gt;:`, `lightningd(&lt;lightningd_pid&gt;):`, `plugin-&lt;plugin_name&gt;:`, `&lt;daemon_name&gt;(&lt;daemon_pid&gt;):`, `jsonrpc:`, `jcon fd &lt;error_fd_to_jsonrpc&gt;:`, `plugin-manager`; 4. `log` is the context of the original log entry. --Note: 1. The main code uses `UNUSUAL`/`BROKEN`, and plugin module uses `warn` /`error`, considering the consistency with plugin, warning choose `warn` /`error`. But users who use c-lightning with plugins may want to `getlog` with specified level when receive warning. It&#39;s the duty for plugin dev to turn `warn`/`error` into `UNUSUAL`/`BROKEN` and present it to the users, or pass it directly to `getlog`; 2. About time, `json_log()` in `log` module uses the Relative Time, from the time when `log_book` inited to the time when this event happend. But I consider the `UNUSUAL`/`BROKEN` event is rare, and it is very likely to happen after running for a long time, so for users, they will pay more attention to Absolute Time. -- Related Change 1. Remove the definitions of `log`, `log_book`, `log_entry` from `log.c` to `log.h`, then they can be used in warning declaration and definition. 2. Remove `void json_add_time(struct json_stream *result, const char *fieldname, struct timespec ts)` from `log.c` to `json.c`, and add related declaration in `json.h`. Now the notification function in `notification.c` can call it. 2. Add a pointer to `struct lightningd` in `struct log_book`. This may affect the independence of the `log` module, but storing a pointer to `ld` is more direct;
5 years ago
void notify_warning(struct lightningd *ld, struct log_entry *l);
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */