| 979 | } |
| 980 | |
| 981 | char *arg_log_to_file(const char *arg, struct lightningd *ld) |
| 982 | { |
| 983 | int size; |
| 984 | struct log_file *logf; |
| 985 | |
| 986 | if (!ld->logfiles) { |
| 987 | setup_log_rotation(ld); |
| 988 | ld->logfiles = tal_arr(ld, const char *, 0); |
| 989 | ld->log_book->log_files = tal_arr(ld->log_book, struct log_file *, 0); |
| 990 | } |
| 991 | |
| 992 | logf = tal(ld->log_book->log_files, struct log_file); |
| 993 | list_head_init(&logf->print_filters); |
| 994 | if (streq(arg, "-")) |
| 995 | logf->f = stdout; |
| 996 | else { |
| 997 | logf->f = fopen(arg, "a"); |
| 998 | if (!logf->f) |
| 999 | return tal_fmt(tmpctx, "Failed to open: %s", strerror(errno)); |
| 1000 | } |
| 1001 | |
| 1002 | tal_arr_expand(&ld->logfiles, tal_strdup(ld->logfiles, arg)); |
| 1003 | tal_arr_expand(&ld->log_book->log_files, logf); |
| 1004 | |
| 1005 | /* For convenience make a block of empty lines just like Bitcoin Core */ |
| 1006 | size = ftell(logf->f); |
| 1007 | if (size > 0) |
| 1008 | fprintf(logf->f, "\n\n\n\n"); |
| 1009 | |
| 1010 | log_debug(ld->log, "Opened log file %s", arg); |
| 1011 | return NULL; |
| 1012 | } |
| 1013 | |
| 1014 | void opt_register_logging(struct lightningd *ld) |
| 1015 | { |