forked from veos-sxarr-NEC/veosinfo_source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
veosinfo_log.c
88 lines (78 loc) · 2.33 KB
/
veosinfo_log.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* Copyright (C) 2017-2018 NEC Corporation
* This file is part of the VEOS information library.
*
* The VEOS information library is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* The VEOS information library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the VEOS information library; if not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file veosinfo_log.c
* @brief Handles the debugging messages of veosinfo library.
*
* @internal
* @author RPM command
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include "veosinfo_log.h"
#define VE_RPMLIB_LOG_CATEGORY "veos.command.libveosinfo"
static log4c_category_t *category;
static pthread_mutex_t log_mtx;
__attribute__ ((constructor))
static void ve_rpmlib_constructor(void)
{
errno = 0;
pthread_mutex_init(&log_mtx, NULL);
/*
* There is no harm calling log4c_init() multiple times
* in the same process.
*/
if (log4c_init())
fprintf(stderr, "Log4c initialization failed.\n");
category = log4c_category_get(VE_RPMLIB_LOG_CATEGORY);
}
void ve_rpmlib__vlog(int prio, const log4c_location_info_t *loc, const char *fmt,
va_list list)
{
pthread_mutex_lock(&log_mtx);
if (log4c_category_is_priority_enabled(category, prio))
__log4c_category_vlog(category, loc, prio, fmt, list);
pthread_mutex_unlock(&log_mtx);
}
void ve_rpmlib__log(int prio, const log4c_location_info_t *loc, const char *fmt,
...)
{
va_list ap;
va_start(ap, fmt);
ve_rpmlib__vlog(prio, loc, fmt, ap);
va_end(ap);
}
__attribute__ ((destructor))
static void ve_rpmlib_destructor(void)
{
/*
* log4c_fini() always returns 0.
* However according to the documentation, it's recommended
* to check the return value.
*/
if (log4c_fini())
fprintf(stderr, "Log4c destructor failed.\n");
pthread_mutex_destroy(&log_mtx);
}