1 /* log.c - Diagnostic and error logging
2 * Copyright 2000-2004 srvx Development Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. Important limitations are
8 * listed in the COPYING file that accompanies this software.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, email srvx-maintainers@srvx.net.
21 #include "helpfile.h" /* send_message, message_register, etc */
24 struct logDestination;
26 struct logDest_vtable {
27 const char *type_name;
28 struct logDestination* (*open)(const char *args);
29 void (*reopen)(struct logDestination *self);
30 void (*close)(struct logDestination *self);
31 void (*log_audit)(struct logDestination *self, struct log_type *type, struct logEntry *entry);
32 void (*log_replay)(struct logDestination *self, struct log_type *type, int is_write, const char *line);
33 void (*log_module)(struct logDestination *self, struct log_type *type, enum log_severity sev, const char *message);
36 struct logDestination {
37 struct logDest_vtable *vtbl;
42 DECLARE_LIST(logList, struct logDestination*);
46 struct logList logs[LOG_NUM_SEVERITIES];
47 struct logEntry *log_oldest;
48 struct logEntry *log_newest;
49 unsigned int log_count;
51 unsigned int max_count;
52 unsigned int default_set : 1;
55 static const char *log_severity_names[] = {
68 static struct dict *log_dest_types;
69 static struct dict *log_dests;
70 static struct dict *log_types;
71 static struct log_type *log_default;
72 static int log_inited, log_debugged;
74 DEFINE_LIST(logList, struct logDestination*);
75 static void log_format_audit(struct logEntry *entry);
76 static const struct message_entry msgtab[] = {
77 { "MSG_INVALID_FACILITY", "$b%s$b is an invalid log facility." },
78 { "MSG_INVALID_SEVERITY", "$b%s$b is an invalid severity level." },
82 static struct logDestination *
83 log_open(const char *name)
85 struct logDest_vtable *vtbl;
86 struct logDestination *ld;
90 if ((ld = dict_find(log_dests, name, NULL))) {
94 if ((sep = strchr(name, ':'))) {
95 memcpy(type_name, name, sep-name);
96 type_name[sep-name] = 0;
98 strcpy(type_name, name);
100 if (!(vtbl = dict_find(log_dest_types, type_name, NULL))) {
101 log_module(MAIN_LOG, LOG_ERROR, "Invalid log type for log '%s'.", name);
104 if (!(ld = vtbl->open(sep ? sep+1 : 0)))
106 ld->name = strdup(name);
107 dict_insert(log_dests, ld->name, ld);
113 logList_open(struct logList *ll, struct record_data *rd)
115 struct logDestination *ld;
122 if ((ld = log_open(rd->d.qstring)))
123 logList_append(ll, ld);
125 case RECDB_STRING_LIST:
126 for (ii=0; ii<rd->d.slist->used; ++ii) {
127 if ((ld = log_open(rd->d.slist->list[ii])))
128 logList_append(ll, ld);
137 logList_join(struct logList *target, const struct logList *source)
139 unsigned int ii, jj, kk;
144 target->used += source->used;
145 target->size += source->used;
146 target->list = realloc(target->list, target->size * sizeof(target->list[0]));
147 for (ii = 0; ii < source->used; ++ii, ++jj) {
149 for (dup = 0, kk = 0; kk < jj; kk++) {
150 if (target->list[kk] == source->list[ii]) {
160 target->list[jj] = source->list[ii];
161 target->list[jj]->refcnt++;
166 logList_close(struct logList *ll)
169 for (ii=0; ii<ll->used; ++ii) {
170 if (!--ll->list[ii]->refcnt) {
171 struct logDestination *ld = ll->list[ii];
183 enum log_severity ls;
185 for (it = dict_first(log_types); it; it = iter_next(it)) {
187 for (ls = 0; ls < LOG_NUM_SEVERITIES; ls++) {
188 logList_close(<->logs[ls]);
190 lt->logs[ls].size = 0;
191 lt->logs[ls].used = 0;
192 lt->logs[ls].list = 0;
198 log_type_free_oldest(struct log_type *lt)
200 struct logEntry *next;
204 next = lt->log_oldest->next;
205 free(lt->log_oldest->default_desc);
206 free(lt->log_oldest);
207 lt->log_oldest = next;
212 log_type_free(void *ptr)
214 struct log_type *lt = ptr;
216 while (lt->log_oldest)
217 log_type_free_oldest(lt);
226 dict_delete(log_types);
227 dict_delete(log_dests);
228 dict_delete(log_dest_types);
231 static enum log_severity
232 find_severity(const char *text)
234 enum log_severity ls;
235 for (ls = 0; ls < LOG_NUM_SEVERITIES; ++ls)
236 if (!ircncasecmp(text, log_severity_names[ls], strlen(log_severity_names[ls])))
238 return LOG_NUM_SEVERITIES;
241 /* Log keys are based on syslog.conf syntax:
242 * KEY := LOGSET '.' SEVSET
243 * LOGSET := LOGLIT | LOGLIT ',' LOGSET
244 * LOGLIT := a registered log type
245 * SEVSET := '*' | SEVLIT | '<' SEVLIT | '<=' SEVLIT | '>' SEVLIT | '>=' SEVLIT | SEVLIG ',' SEVSET
246 * SEVLIT := one of log_severity_names
247 * A KEY contains the Cartesian product of the logs in its LOGSET
248 * and the severities in its SEVSET.
252 log_parse_logset(char *buffer, struct string_list *slist)
256 char *cont = strchr(buffer, ',');
259 string_list_append(slist, strdup(buffer));
265 log_parse_sevset(char *buffer, char targets[LOG_NUM_SEVERITIES])
267 memset(targets, 0, LOG_NUM_SEVERITIES);
270 enum log_severity bound;
273 cont = strchr(buffer, ',');
274 if (cont) *cont++ = 0;
275 if (buffer[0] == '*' && buffer[1] == 0) {
276 for (bound = 0; bound < LOG_NUM_SEVERITIES; bound++) {
277 /* make people explicitly specify replay targets */
278 if (bound != LOG_REPLAY)
281 } else if (buffer[0] == '<') {
282 if (buffer[1] == '=')
283 bound = find_severity(buffer+2) + 1;
285 bound = find_severity(buffer+1);
286 for (first = 1; bound > 0; bound--) {
287 /* make people explicitly specify replay targets */
288 if (bound != LOG_REPLAY || first) {
293 } else if (buffer[0] == '>') {
294 if (buffer[1] == '=')
295 bound = find_severity(buffer+2);
297 bound = find_severity(buffer+1) + 1;
298 for (first = 1; bound < LOG_NUM_SEVERITIES; bound++) {
299 /* make people explicitly specify replay targets */
300 if (bound != LOG_REPLAY || first) {
306 bound = find_severity(buffer);
314 log_parse_cross(const char *buffer, struct string_list *types, char sevset[LOG_NUM_SEVERITIES])
318 dup = strdup(buffer);
319 sep = strchr(dup, '.');
321 log_parse_logset(dup, types);
322 log_parse_sevset(sep, sevset);
327 log_parse_options(struct log_type *type, struct dict *conf)
330 opt = database_get_data(conf, "max_age", RECDB_QSTRING);
332 type->max_age = ParseInterval(opt);
333 opt = database_get_data(conf, "max_count", RECDB_QSTRING);
335 type->max_count = strtoul(opt, NULL, 10);
341 struct record_data *rd, *rd2;
344 struct log_type *type;
345 enum log_severity sev;
349 dict_delete(log_dests);
351 log_dests = dict_new();
352 dict_set_free_keys(log_dests, free);
354 rd = conf_get_node("logs");
355 if (rd && (rd->type == RECDB_OBJECT)) {
356 for (it = dict_first(rd->d.object); it; it = iter_next(it)) {
357 if ((sep = strchr(iter_key(it), '.'))) {
358 struct logList logList;
359 char sevset[LOG_NUM_SEVERITIES];
360 struct string_list *slist;
362 /* It looks like a <type>.<severity> record. Try to parse it. */
363 slist = alloc_string_list(4);
364 log_parse_cross(iter_key(it), slist, sevset);
366 logList_open(&logList, iter_data(it));
367 for (ii = 0; ii < slist->used; ++ii) {
368 type = log_register_type(slist->list[ii], NULL);
369 for (sev = 0; sev < LOG_NUM_SEVERITIES; ++sev) {
370 if (!sevset[sev]) continue;
371 logList_join(&type->logs[sev], &logList);
374 logList_close(&logList);
375 free_string_list(slist);
376 } else if ((rd2 = iter_data(it))
377 && (rd2->type == RECDB_OBJECT)
378 && (type = log_register_type(iter_key(it), NULL))) {
379 log_parse_options(type, rd2->d.object);
381 log_module(MAIN_LOG, LOG_ERROR, "Unknown logs subkey '%s'.", iter_key(it));
392 enum log_severity sev;
393 struct logDestination *log_stdout;
394 struct logList target;
396 log_stdout = log_open("std:out");
397 logList_init(&target);
398 logList_append(&target, log_stdout);
400 for (sev = 0; sev < LOG_NUM_SEVERITIES; ++sev)
401 logList_join(&log_default->logs[sev], &target);
403 logList_close(&target);
411 for (it = dict_first(log_dests); it; it = iter_next(it)) {
412 struct logDestination *ld = iter_data(it);
413 ld->vtbl->reopen(ld);
418 log_register_type(const char *name, const char *default_log)
420 struct log_type *type;
421 struct logDestination *dest;
422 enum log_severity sev;
424 if (!(type = dict_find(log_types, name, NULL))) {
425 type = calloc(1, sizeof(*type));
426 type->name = strdup(name);
428 type->max_count = 1024;
429 dict_insert(log_types, type->name, type);
431 if (default_log && !type->default_set) {
432 /* If any severity level was unspecified in the config, use the default. */
434 for (sev = 0; sev < LOG_NUM_SEVERITIES; ++sev) {
435 if (sev == LOG_REPLAY)
436 continue; /* never default LOG_REPLAY */
437 if (!type->logs[sev].size) {
438 logList_init(&type->logs[sev]);
440 if (!(dest = log_open(default_log)))
444 logList_append(&type->logs[sev], dest);
448 type->default_set = 1;
453 /* logging functions */
456 log_audit(struct log_type *type, enum log_severity sev, struct userNode *user, struct userNode *bot, const char *channel_name, unsigned int flags, const char *command)
458 struct logEntry *entry;
459 unsigned int size, ii;
462 /* First make sure severity is appropriate */
463 if ((sev != LOG_COMMAND) && (sev != LOG_OVERRIDE) && (sev != LOG_STAFF)) {
464 log_module(MAIN_LOG, LOG_ERROR, "Illegal audit severity %d", sev);
467 /* Allocate and fill in the log entry */
468 size = sizeof(*entry) + strlen(user->nick) + strlen(command) + 2;
469 if (user->handle_info)
470 size += strlen(user->handle_info->handle) + 1;
472 size += strlen(channel_name) + 1;
473 if (flags & AUDIT_HOSTMASK)
474 size += strlen(user->ident) + strlen(user->hostname) + 2;
475 entry = calloc(1, size);
476 str_next = (char*)(entry + 1);
481 size = strlen(channel_name) + 1;
482 entry->channel_name = memcpy(str_next, channel_name, size);
486 size = strlen(user->nick) + 1;
487 entry->user_nick = memcpy(str_next, user->nick, size);
490 if (user->handle_info) {
491 size = strlen(user->handle_info->handle) + 1;
492 entry->user_account = memcpy(str_next, user->handle_info->handle, size);
495 if (flags & AUDIT_HOSTMASK) {
496 size = sprintf(str_next, "%s@%s", user->ident, user->hostname) + 1;
497 entry->user_hostmask = str_next;
500 entry->user_hostmask = 0;
503 size = strlen(command) + 1;
504 entry->command = memcpy(str_next, command, size);
508 /* fill in the default text for the event */
509 log_format_audit(entry);
511 /* insert into the linked list */
513 entry->prev = type->log_newest;
514 if (type->log_newest)
515 type->log_newest->next = entry;
517 type->log_oldest = entry;
518 type->log_newest = entry;
521 /* remove old elements from the linked list */
522 while (type->log_count > type->max_count)
523 log_type_free_oldest(type);
524 while (type->log_oldest && (type->log_oldest->time + type->max_age < (unsigned long)now))
525 log_type_free_oldest(type);
526 if (type->log_oldest)
527 type->log_oldest->prev = 0;
529 type->log_newest = 0;
531 /* call the destination logs */
532 for (ii=0; ii<type->logs[sev].used; ++ii) {
533 struct logDestination *ld = type->logs[sev].list[ii];
534 ld->vtbl->log_audit(ld, type, entry);
536 for (ii=0; ii<log_default->logs[sev].used; ++ii) {
537 struct logDestination *ld = log_default->logs[sev].list[ii];
538 ld->vtbl->log_audit(ld, type, entry);
543 log_replay(struct log_type *type, int is_write, const char *line)
547 for (ii=0; ii<type->logs[LOG_REPLAY].used; ++ii) {
548 struct logDestination *ld = type->logs[LOG_REPLAY].list[ii];
549 ld->vtbl->log_replay(ld, type, is_write, line);
551 for (ii=0; ii<log_default->logs[LOG_REPLAY].used; ++ii) {
552 struct logDestination *ld = log_default->logs[LOG_REPLAY].list[ii];
553 ld->vtbl->log_replay(ld, type, is_write, line);
558 log_module(struct log_type *type, enum log_severity sev, const char *format, ...)
564 if (sev > LOG_FATAL) {
565 log_module(MAIN_LOG, LOG_ERROR, "Illegal log_module severity %d", sev);
568 va_start(args, format);
569 vsnprintf(msgbuf, sizeof(msgbuf), format, args);
572 for (ii=0; ii<type->logs[sev].used; ++ii) {
573 struct logDestination *ld = type->logs[sev].list[ii];
574 ld->vtbl->log_module(ld, type, sev, msgbuf);
576 for (ii=0; ii<log_default->logs[sev].used; ++ii) {
577 struct logDestination *ld = log_default->logs[sev].list[ii];
578 ld->vtbl->log_module(ld, type, sev, msgbuf);
581 /* Special behavior before we start full operation */
582 fprintf(stderr, "%s: %s\n", log_severity_names[sev], msgbuf);
586 /* audit log searching */
589 log_discrim_create(struct userNode *service, struct userNode *user, unsigned int argc, char *argv[])
592 struct logSearch *discrim;
594 /* Assume all criteria require arguments. */
597 send_message(user, service, "MSG_MISSING_PARAMS", argv[0]);
601 discrim = malloc(sizeof(struct logSearch));
602 memset(discrim, 0, sizeof(*discrim));
604 discrim->max_time = INT_MAX;
605 discrim->severities = ~0;
607 for (ii=1; ii<argc-1; ii++) {
608 if (!irccasecmp(argv[ii], "bot")) {
609 struct userNode *bot = GetUserH(argv[++ii]);
611 send_message(user, service, "MSG_NICK_UNKNOWN", argv[ii]);
613 } else if (!IsLocal(bot)) {
614 send_message(user, service, "MSG_NOT_A_SERVICE", argv[ii]);
617 discrim->masks.bot = bot;
618 } else if (!irccasecmp(argv[ii], "channel")) {
619 discrim->masks.channel_name = argv[++ii];
620 } else if (!irccasecmp(argv[ii], "nick")) {
621 discrim->masks.user_nick = argv[++ii];
622 } else if (!irccasecmp(argv[ii], "account")) {
623 discrim->masks.user_account = argv[++ii];
624 } else if (!irccasecmp(argv[ii], "hostmask")) {
625 discrim->masks.user_hostmask = argv[++ii];
626 } else if (!irccasecmp(argv[ii], "command")) {
627 discrim->masks.command = argv[++ii];
628 } else if (!irccasecmp(argv[ii], "age")) {
629 const char *cmp = argv[++ii];
632 discrim->min_time = now - ParseInterval(cmp+2);
634 discrim->min_time = now - (ParseInterval(cmp+1) - 1);
635 } else if (cmp[0] == '>') {
637 discrim->max_time = now - ParseInterval(cmp+2);
639 discrim->max_time = now - (ParseInterval(cmp+1) - 1);
641 discrim->min_time = now - ParseInterval(cmp+2);
643 } else if (!irccasecmp(argv[ii], "limit")) {
644 discrim->limit = strtoul(argv[++ii], NULL, 10);
645 } else if (!irccasecmp(argv[ii], "level")) {
646 char *severity = argv[++ii];
647 discrim->severities = 0;
649 enum log_severity sev = find_severity(severity);
650 if (sev == LOG_NUM_SEVERITIES) {
651 send_message(user, service, "MSG_INVALID_SEVERITY", severity);
654 discrim->severities |= 1 << sev;
655 severity = strchr(severity, ',');
660 } else if (!irccasecmp(argv[ii], "type")) {
661 if (!(discrim->type = dict_find(log_types, argv[++ii], NULL))) {
662 send_message(user, service, "MSG_INVALID_FACILITY", argv[ii]);
666 send_message(user, service, "MSG_INVALID_CRITERIA", argv[ii]);
678 entry_match(struct logSearch *discrim, struct logEntry *entry)
680 if ((entry->time < discrim->min_time)
681 || (entry->time > discrim->max_time)
682 || !(discrim->severities & (1 << entry->slvl))
683 || (discrim->masks.bot && (discrim->masks.bot != entry->bot))
684 /* don't do glob matching, so that !events #a*b does not match #acb */
685 || (discrim->masks.channel_name
686 && (!entry->channel_name
687 || irccasecmp(entry->channel_name, discrim->masks.channel_name)))
688 || (discrim->masks.user_nick
689 && !match_ircglob(entry->user_nick, discrim->masks.user_nick))
690 || (discrim->masks.user_account
691 && (!entry->user_account
692 || !match_ircglob(entry->user_account, discrim->masks.user_account)))
693 || (discrim->masks.user_hostmask
694 && entry->user_hostmask
695 && !match_ircglob(entry->user_hostmask, discrim->masks.user_hostmask))
696 || (discrim->masks.command
697 && !match_ircglob(entry->command, discrim->masks.command))) {
704 log_report_entry(struct logEntry *match, void *extra)
706 struct logReport *rpt = extra;
707 send_message_type(4, rpt->user, rpt->reporter, "%s", match->default_desc);
711 log_entry_search(struct logSearch *discrim, entry_search_func esf, void *data)
713 unsigned int matched = 0;
716 struct logEntry *entry;
718 for (entry = discrim->type->log_oldest; entry; entry = entry->next) {
719 if (entry_match(discrim, entry)) {
721 if (++matched >= discrim->limit)
728 for (it = dict_first(log_types); it; it = iter_next(it)) {
729 discrim->type = iter_data(it);
730 matched += log_entry_search(discrim, esf, data);
737 /* generic helper functions */
740 log_format_timestamp(time_t when, struct string_buffer *sbuf)
743 localtime_r(&when, &local);
744 if (sbuf->size < 24) {
747 sbuf->list = calloc(1, 24);
749 sbuf->used = sprintf(sbuf->list, "[%02d:%02d:%02d %02d/%02d/%04d]", local.tm_hour, local.tm_min, local.tm_sec, local.tm_mon+1, local.tm_mday, local.tm_year+1900);
753 log_format_audit(struct logEntry *entry)
755 struct string_buffer sbuf;
756 memset(&sbuf, 0, sizeof(sbuf));
757 log_format_timestamp(entry->time, &sbuf);
758 string_buffer_append_string(&sbuf, " (");
759 string_buffer_append_string(&sbuf, entry->bot->nick);
760 if (entry->channel_name) {
761 string_buffer_append(&sbuf, ':');
762 string_buffer_append_string(&sbuf, entry->channel_name);
764 string_buffer_append_string(&sbuf, ") [");
765 string_buffer_append_string(&sbuf, entry->user_nick);
766 if (entry->user_hostmask) {
767 string_buffer_append(&sbuf, '!');
768 string_buffer_append_string(&sbuf, entry->user_hostmask);
770 if (entry->user_account) {
771 string_buffer_append(&sbuf, ':');
772 string_buffer_append_string(&sbuf, entry->user_account);
774 string_buffer_append_string(&sbuf, "]: ");
775 string_buffer_append_string(&sbuf, entry->command);
776 entry->default_desc = strdup(sbuf.list);
780 /* shared stub log operations act as a noop */
783 ldNop_reopen(UNUSED_ARG(struct logDestination *self_)) {
784 /* no operation necessary */
788 ldNop_replay(UNUSED_ARG(struct logDestination *self_), UNUSED_ARG(struct log_type *type), UNUSED_ARG(int is_write), UNUSED_ARG(const char *line)) {
789 /* no operation necessary */
794 struct logDest_file {
795 struct logDestination base;
799 static struct logDest_vtable ldFile_vtbl;
801 static struct logDestination *
802 ldFile_open(const char *args) {
803 struct logDest_file *ld;
804 ld = calloc(1, sizeof(*ld));
805 ld->base.vtbl = &ldFile_vtbl;
806 ld->fname = strdup(args);
807 ld->output = fopen(ld->fname, "a");
812 ldFile_reopen(struct logDestination *self_) {
813 struct logDest_file *self = (struct logDest_file*)self_;
814 fclose(self->output);
815 self->output = fopen(self->fname, "a");
819 ldFile_close(struct logDestination *self_) {
820 struct logDest_file *self = (struct logDest_file*)self_;
821 fclose(self->output);
827 ldFile_audit(struct logDestination *self_, UNUSED_ARG(struct log_type *type), struct logEntry *entry) {
828 struct logDest_file *self = (struct logDest_file*)self_;
829 fputs(entry->default_desc, self->output);
830 fputc('\n', self->output);
831 fflush(self->output);
835 ldFile_replay(struct logDestination *self_, UNUSED_ARG(struct log_type *type), int is_write, const char *line) {
836 struct logDest_file *self = (struct logDest_file*)self_;
837 struct string_buffer sbuf;
838 memset(&sbuf, 0, sizeof(sbuf));
839 log_format_timestamp(now, &sbuf);
840 string_buffer_append_string(&sbuf, is_write ? "W: " : " ");
841 string_buffer_append_string(&sbuf, line);
842 fputs(sbuf.list, self->output);
843 fputc('\n', self->output);
845 fflush(self->output);
849 ldFile_module(struct logDestination *self_, struct log_type *type, enum log_severity sev, const char *message) {
850 struct logDest_file *self = (struct logDest_file*)self_;
851 struct string_buffer sbuf;
852 memset(&sbuf, 0, sizeof(sbuf));
853 log_format_timestamp(now, &sbuf);
854 fprintf(self->output, "%s (%s:%s) %s\n", sbuf.list, type->name, log_severity_names[sev], message);
856 fflush(self->output);
859 static struct logDest_vtable ldFile_vtbl = {
871 static struct logDest_vtable ldStd_vtbl;
873 static struct logDestination *
874 ldStd_open(const char *args) {
875 struct logDest_file *ld;
876 ld = calloc(1, sizeof(*ld));
877 ld->base.vtbl = &ldStd_vtbl;
878 ld->fname = strdup(args);
880 /* Print to stderr if given "err" and default to stdout otherwise. */
882 ld->output = fdopen(atoi(args), "a");
883 else if (!strcasecmp(args, "err"))
892 ldStd_close(struct logDestination *self_) {
893 struct logDest_file *self = (struct logDest_file*)self_;
899 ldStd_replay(struct logDestination *self_, UNUSED_ARG(struct log_type *type), int is_write, const char *line) {
900 struct logDest_file *self = (struct logDest_file*)self_;
901 fprintf(self->output, "%s%s\n", is_write ? "W: " : " ", line);
905 ldStd_module(struct logDestination *self_, UNUSED_ARG(struct log_type *type), enum log_severity sev, const char *message) {
906 struct logDest_file *self = (struct logDest_file*)self_;
907 fprintf(self->output, "%s: %s\n", log_severity_names[sev], message);
910 static struct logDest_vtable ldStd_vtbl = {
923 struct logDestination base;
926 static struct logDest_vtable ldIrc_vtbl;
928 static struct logDestination *
929 ldIrc_open(const char *args) {
930 struct logDest_irc *ld;
931 ld = calloc(1, sizeof(*ld));
932 ld->base.vtbl = &ldIrc_vtbl;
933 ld->target = strdup(args);
938 ldIrc_close(struct logDestination *self_) {
939 struct logDest_irc *self = (struct logDest_irc*)self_;
945 ldIrc_audit(struct logDestination *self_, UNUSED_ARG(struct log_type *type), struct logEntry *entry) {
946 struct logDest_irc *self = (struct logDest_irc*)self_;
948 if (entry->channel_name) {
949 send_target_message(4, self->target, entry->bot, "(%s", strchr(strchr(entry->default_desc, ' '), ':')+1);
951 send_target_message(4, self->target, entry->bot, "%s", strchr(entry->default_desc, ')')+2);
956 ldIrc_module(struct logDestination *self_, struct log_type *type, enum log_severity sev, const char *message) {
957 struct logDest_irc *self = (struct logDest_irc*)self_;
958 extern struct userNode *opserv;
960 send_target_message(4, self->target, opserv, "%s %s: %s\n", type->name, log_severity_names[sev], message);
963 static struct logDest_vtable ldIrc_vtbl = {
969 ldNop_replay, /* totally ignore this - it would be a recipe for disaster */
976 log_types = dict_new();
977 dict_set_free_keys(log_types, free);
978 dict_set_free_data(log_types, log_type_free);
979 log_dest_types = dict_new();
980 /* register log types */
981 dict_insert(log_dest_types, ldFile_vtbl.type_name, &ldFile_vtbl);
982 dict_insert(log_dest_types, ldStd_vtbl.type_name, &ldStd_vtbl);
983 dict_insert(log_dest_types, ldIrc_vtbl.type_name, &ldIrc_vtbl);
984 conf_register_reload(log_conf_read);
985 log_default = log_register_type("*", NULL);
986 reg_exit_func(cleanup_logs);
987 message_register_table(msgtab);