summaryrefslogtreecommitdiff
path: root/tools/thermal/lib/log.c
blob: 597d6e7f78580fb622983c5808930332cc58ec23 (plain)
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
// SPDX-License-Identifier: LGPL-2.1+
// Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include "log.h"

static const char *__ident = "unknown";
static int __options;

static const char * const loglvl[] = {
	[LOG_DEBUG]	= "DEBUG",
	[LOG_INFO]	= "INFO",
	[LOG_NOTICE]	= "NOTICE",
	[LOG_WARNING]	= "WARN",
	[LOG_ERR]	= "ERROR",
	[LOG_CRIT]	= "CRITICAL",
	[LOG_ALERT]	= "ALERT",
	[LOG_EMERG]	= "EMERG",
};

int log_str2level(const char *lvl)
{
	int i;

	for (i = 0; i < sizeof(loglvl) / sizeof(loglvl[LOG_DEBUG]); i++)
		if (!strcmp(lvl, loglvl[i]))
			return i;

	return LOG_DEBUG;
}

extern void logit(int level, const char *format, ...)
{
	va_list args;

	va_start(args, format);

	if (__options & TO_SYSLOG)
		vsyslog(level, format, args);

	if (__options & TO_STDERR)
		vfprintf(stderr, format, args);

	if (__options & TO_STDOUT)
		vfprintf(stdout, format, args);

	va_end(args);
}

int log_init(int level, const char *ident, int options)
{
	if (!options)
		return -1;

	if (level > LOG_DEBUG)
		return -1;

	if (!ident)
		return -1;

	__ident = ident;
	__options = options;

	if (options & TO_SYSLOG) {
		openlog(__ident, options | LOG_NDELAY, LOG_USER);
		setlogmask(LOG_UPTO(level));
	}

	return 0;
}

void log_exit(void)
{
	closelog();
}
> 2025-10-19perf tools: Add fallback for exclude_guestNamhyung Kim 2025-10-19perf session: Fix handling when buffer exceeds 2 GiBLeo Yan 2025-10-19perf arm_spe: Correct memory level for remote accessLeo Yan 2025-10-19perf arm-spe: Rename the common data source encodingLeo Yan 2025-10-19perf arm_spe: Correct setting remote accessLeo Yan 2025-10-19perf util: Fix compression checks returning -1 as boolYunseong Kim 2025-10-19perf evsel: Avoid container_of on a NULL leaderIan Rogers 2025-10-19perf disasm: Avoid undefined behavior in incrementing NULLIan Rogers 2025-09-09perf bpf-utils: Harden get_bpf_prog_info_linearIan Rogers 2025-09-09perf bpf-utils: Constify bpil_array_descIan Rogers 2025-09-09perf bpf-event: Fix use-after-free in synthesisIan Rogers 2025-09-04perf symbol-minimal: Fix ehdr reading in filename__read_build_idIan Rogers 2025-08-15perf record: Cache build-ID of hit DSOs onlyNamhyung Kim 2025-08-15perf sched: Fix memory leaks for evsel->priv in timehistNamhyung Kim 2025-08-15perf dso: Add missed dso__put to dso__load_kcoreIan Rogers 2025-06-27perf evsel: Missed close() when probing hybrid core PMUsIan Rogers 2025-06-19perf callchain: Always populate the addr_location map when adding IPIan Rogers 2025-06-19perf symbol: Fix use-after-free in filename__read_build_idIan Rogers 2025-06-19perf intel-pt: Fix PEBS-via-PT data_srcAdrian Hunter 2025-06-19perf symbol-minimal: Fix double free in filename__read_build_idIan Rogers