コード例 #1
0
ファイル: log.c プロジェクト: 8Media/icecast-kh
void log_write(int log_id, unsigned priority, const char *cat, const char *func, 
        const char *fmt, ...)
{
    static char *prior[] = { "EROR", "WARN", "INFO", "DBUG" };
    int datelen;
    time_t now;
    char pre[256];
    char line[LOG_MAXLINELEN];
    va_list ap;

    if (log_id < 0 || log_id >= LOG_MAXLOGS) return; /* Bad log number */
    if (loglist[log_id].level < priority) return;
    if (priority > sizeof(prior)/sizeof(prior[0])) return; /* Bad priority */

    va_start(ap, fmt);
    vsnprintf(line, LOG_MAXLINELEN, fmt, ap);

    now = time(NULL);

    _lock_logger();
    datelen = strftime (pre, sizeof (pre), "[%Y-%m-%d  %H:%M:%S]", localtime(&now)); 

    snprintf (pre+datelen, sizeof (pre)-datelen, " %s %s%s ", prior [priority-1], cat, func);

    if (_log_open (log_id, now))
    {
        int len = create_log_entry (log_id, pre, line);
        if (len > 0)
            loglist[log_id].size += len;
    }
    _unlock_logger();

    va_end(ap);
}
コード例 #2
0
ファイル: log.c プロジェクト: 8Media/icecast-kh
void log_write_direct(int log_id, const char *fmt, ...)
{
    va_list ap;
    time_t now;
    char line[LOG_MAXLINELEN];

    if (log_id < 0 || log_id >= LOG_MAXLOGS) return;
    
    va_start(ap, fmt);

    now = time(NULL);

    _lock_logger();
    vsnprintf(line, LOG_MAXLINELEN, fmt, ap);
    if (_log_open (log_id, now))
    {
        int len = create_log_entry (log_id, "", line);
        if (len > 0)
            loglist[log_id].size += len;
    }
    _unlock_logger();

    va_end(ap);

    fflush(loglist[log_id].logfile);
}
コード例 #3
0
ファイル: liblog.c プロジェクト: opensvn/libraries
static ssize_t _log_write(struct iovec *vec, int n)
{
    unsigned long long tmp_size = get_file_size(_log_name);
    if (UNLIKELY(tmp_size > _log_file_size)) {
        fprintf(stderr, "%s size= %llu reach max %llu, splited\n",
                _log_name, tmp_size, _log_file_size);
        if (-1 == _log_close()) {
            fprintf(stderr, "_log_close errno:%d", errno);
        }
        log_get_time(_log_name_time, sizeof(_log_name_time), 1);
        snprintf(_log_name, sizeof(_log_name), "%s%s_%s",
                _log_path, _log_name_prefix, _log_name_time);

        _log_open(_log_name);
        fprintf(stderr, "splited file %s\n", _log_name);
    }

    return writev(_log_fd, vec, n);
}
コード例 #4
0
ファイル: liblog.c プロジェクト: gozfree/libraries
static ssize_t _log_write(struct iovec *vec, int n)
{
    char log_rename[FILENAME_LEN] = {0};
    unsigned long long tmp_size = get_file_size(_log_name);
    if (UNLIKELY(tmp_size > _log_file_size)) {
        fprintf(stderr, "%s size= %llu reach max %llu, splited\n",
                _log_name, tmp_size, _log_file_size);
        if (-1 == _log_close()) {
            fprintf(stderr, "_log_close errno:%d", errno);
        }
        log_get_time(_log_name_time, sizeof(_log_name_time), 1);
        snprintf(log_rename, sizeof(log_rename), "%s%s_%s",
                _log_path, _log_name_prefix, _log_name_time);
        if (-1 == rename(_log_name, log_rename)) {
            fprintf(stderr, "log file splited %s error: %d:%s\n",
                    log_rename, errno , strerror(errno));
        }
        _log_open(_log_name);
        fprintf(stderr, "splited file %s\n", log_rename);
    }

    return writev(_log_fd, vec, n);
}