plugin: Give each plugin their own log-prefix

There is no good naming just yet, so we just number them 1 to n.
This commit is contained in:
Christian Decker 2018-11-11 10:09:02 +01:00
parent 74c58e9f25
commit b02861bfe1
4 changed files with 14 additions and 5 deletions

View file

@ -217,7 +217,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
*code. Here we initialize the context that will keep track and control *code. Here we initialize the context that will keep track and control
*the plugins. *the plugins.
*/ */
ld->plugins = plugins_new(ld, ld->log); ld->plugins = plugins_new(ld, ld->log_book);
return ld; return ld;
} }

View file

@ -56,6 +56,7 @@ struct plugins {
/* Currently pending requests by their request ID */ /* Currently pending requests by their request ID */
UINTMAP(struct plugin_request *) pending_requests; UINTMAP(struct plugin_request *) pending_requests;
struct log *log; struct log *log;
struct log_book *log_book;
}; };
struct json_output { struct json_output {
@ -72,21 +73,29 @@ struct plugin_opt {
char *value; char *value;
}; };
struct plugins *plugins_new(const tal_t *ctx, struct log *log){ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book){
struct plugins *p; struct plugins *p;
p = tal(ctx, struct plugins); p = tal(ctx, struct plugins);
list_head_init(&p->plugins); list_head_init(&p->plugins);
p->log = log; p->log_book = log_book;
p->log = new_log(p, log_book, "plugin-manager");
return p; return p;
} }
void plugin_register(struct plugins *plugins, const char* path TAKES) void plugin_register(struct plugins *plugins, const char* path TAKES)
{ {
struct plugin *p; struct plugin *p;
static size_t plugin_count = 0;
p = tal(plugins, struct plugin); p = tal(plugins, struct plugin);
list_add_tail(&plugins->plugins, &p->list); list_add_tail(&plugins->plugins, &p->list);
p->plugins = plugins; p->plugins = plugins;
p->cmd = tal_strdup(p, path); p->cmd = tal_strdup(p, path);
/* FIXME(cdecker): Referring to plugin by their registration
number might not be that useful, come up with a naming scheme
that makes more sense. */
plugin_count++;
p->log = new_log(p, plugins->log_book, "plugin-%zu", plugin_count);
p->log = plugins->log; p->log = plugins->log;
list_head_init(&p->plugin_opts); list_head_init(&p->plugin_opts);
} }

View file

@ -16,7 +16,7 @@ struct plugins;
/** /**
* Create a new plugins context. * Create a new plugins context.
*/ */
struct plugins *plugins_new(const tal_t *ctx, struct log *log); struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book);
/** /**
* Initialize the registered plugins. * Initialize the registered plugins.

View file

@ -129,7 +129,7 @@ void plugins_config(struct plugins *plugins UNNEEDED)
void plugins_init(struct plugins *plugins UNNEEDED) void plugins_init(struct plugins *plugins UNNEEDED)
{ fprintf(stderr, "plugins_init called!\n"); abort(); } { fprintf(stderr, "plugins_init called!\n"); abort(); }
/* Generated stub for plugins_new */ /* Generated stub for plugins_new */
struct plugins *plugins_new(const tal_t *ctx UNNEEDED, struct log *log UNNEEDED) struct plugins *plugins_new(const tal_t *ctx UNNEEDED, struct log_book *log_book UNNEEDED)
{ fprintf(stderr, "plugins_new called!\n"); abort(); } { fprintf(stderr, "plugins_new called!\n"); abort(); }
/* Generated stub for register_opts */ /* Generated stub for register_opts */
void register_opts(struct lightningd *ld UNNEEDED) void register_opts(struct lightningd *ld UNNEEDED)