Browse Source

plugin: Give each plugin their own log-prefix

There is no good naming just yet, so we just number them 1 to n.
trytravis
Christian Decker 6 years ago
parent
commit
b02861bfe1
  1. 2
      lightningd/lightningd.c
  2. 13
      lightningd/plugin.c
  3. 2
      lightningd/plugin.h
  4. 2
      lightningd/test/run-find_my_abspath.c

2
lightningd/lightningd.c

@ -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
*the plugins.
*/
ld->plugins = plugins_new(ld, ld->log);
ld->plugins = plugins_new(ld, ld->log_book);
return ld;
}

13
lightningd/plugin.c

@ -56,6 +56,7 @@ struct plugins {
/* Currently pending requests by their request ID */
UINTMAP(struct plugin_request *) pending_requests;
struct log *log;
struct log_book *log_book;
};
struct json_output {
@ -72,21 +73,29 @@ struct plugin_opt {
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;
p = tal(ctx, struct 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;
}
void plugin_register(struct plugins *plugins, const char* path TAKES)
{
struct plugin *p;
static size_t plugin_count = 0;
p = tal(plugins, struct plugin);
list_add_tail(&plugins->plugins, &p->list);
p->plugins = plugins;
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;
list_head_init(&p->plugin_opts);
}

2
lightningd/plugin.h

@ -16,7 +16,7 @@ struct plugins;
/**
* 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.

2
lightningd/test/run-find_my_abspath.c

@ -129,7 +129,7 @@ void plugins_config(struct plugins *plugins UNNEEDED)
void plugins_init(struct plugins *plugins UNNEEDED)
{ fprintf(stderr, "plugins_init called!\n"); abort(); }
/* 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(); }
/* Generated stub for register_opts */
void register_opts(struct lightningd *ld UNNEEDED)

Loading…
Cancel
Save