示例#1
0
文件: AdminLog.c 项目: CSRedRat/cjdns
static Dict* makeLogMessage(struct Subscription* subscription,
                            struct AdminLog* logger,
                            enum Log_Level logLevel,
                            const char* fullFilePath,
                            uint32_t line,
                            const char* format,
                            va_list vaArgs,
                            struct Allocator* alloc)
{
    time_t now;
    time(&now);

    Dict* out = Dict_new(alloc);
    char* buff = Allocator_malloc(alloc, 20);
    Hex_encode((uint8_t*)buff, 20, subscription->streamId, 8);
    Dict_putString(out, String_new("streamId", alloc), String_new(buff, alloc), alloc);
    Dict_putInt(out, String_new("time", alloc), now, alloc);
    Dict_putString(out,
                   String_new("level", alloc),
                   String_new(Log_nameForLevel(logLevel), alloc),
                   alloc);
    const char* shortName = getShortName(fullFilePath);
    Dict_putString(out, String_new("file", alloc), String_new((char*)shortName, alloc), alloc);
    Dict_putInt(out, String_new("line", alloc), line, alloc);
    String* message = String_vprintf(alloc, format, vaArgs);

    // Strip all of the annoying \n marks in the log entries.
    if (message->len > 0 && message->bytes[message->len - 1] == '\n') {
        message->len--;
    }
    Dict_putString(out, String_new("message", alloc), message, alloc);

    return out;
}
示例#2
0
文件: Log.c 项目: Arceliar/cjdns
enum Log_Level Log_levelForName(char* name)
{
    for (enum Log_Level logLevel = Log_Level_KEYS; logLevel <= Log_Level_CRITICAL; logLevel++) {
        if (!strcasecmp(name, Log_nameForLevel(logLevel))) {
            return logLevel;
        }
    }
    return Log_Level_INVALID;
}