void log_item_add(LOG_REC *log, int type, const char *name, const char *servertag) { LOG_ITEM_REC *rec; g_return_if_fail(log != NULL); g_return_if_fail(name != NULL); if (log_item_find(log, type, name, servertag)) return; rec = g_new0(LOG_ITEM_REC, 1); rec->type = type; rec->name = g_strdup(name); rec->servertag = g_strdup(servertag); log->items = g_slist_append(log->items, rec); }
void log_file_write(const char *server_tag, const char *item, int level, const char *str, int no_fallbacks) { GSList *tmp, *fallbacks; char *tmpstr; int found; g_return_if_fail(str != NULL); if (logs == NULL) return; fallbacks = NULL; found = FALSE; for (tmp = logs; tmp != NULL; tmp = tmp->next) { LOG_REC *rec = tmp->data; if (rec->handle == -1) continue; /* log not opened yet */ if ((level & rec->level) == 0) continue; if (rec->items == NULL) fallbacks = g_slist_append(fallbacks, rec); else if (item != NULL && log_item_find(rec, LOG_ITEM_TARGET, item, server_tag) != NULL) log_write_rec(rec, str, level); } if (!found && !no_fallbacks && fallbacks != NULL) { /* not found from any items, so write it to all main logs */ tmpstr = (level & MSGLEVEL_PUBLIC) && item != NULL ? g_strconcat(item, ": ", str, NULL) : g_strdup(str); for (tmp = fallbacks; tmp != NULL; tmp = tmp->next) log_write_rec(tmp->data, tmpstr, level); g_free(tmpstr); } g_slist_free(fallbacks); }
static LOG_REC *logs_find_item(int type, const char *item, const char *servertag, LOG_ITEM_REC **ret_item) { LOG_ITEM_REC *logitem; GSList *tmp; for (tmp = logs; tmp != NULL; tmp = tmp->next) { LOG_REC *log = tmp->data; if (type == LOG_ITEM_TARGET && log->temp == 0) continue; logitem = log_item_find(log, type, item, servertag); if (logitem != NULL) { if (ret_item != NULL) *ret_item = logitem; return log; } } return NULL; }