summaryrefslogtreecommitdiff
path: root/kern/log.h
blob: 1a05334e27354c3b0f034e8dfa02ba6d40d1cb00 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (c) 2017 Richard Braun.
 *
 * This program 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * System logging.
 */

#ifndef KERN_LOG_H
#define KERN_LOG_H

#include <stdarg.h>


#include <kern/init.h>
enum {
    LOG_EMERG,
    LOG_ALERT,
    LOG_CRIT,
    LOG_ERR,
    LOG_WARNING,
    LOG_NOTICE,
    LOG_INFO,
    LOG_DEBUG,
    LOG_NR_LEVELS,
};

/*
 * Generate a message and send it to the log thread.
 *
 * The arguments and return value are similar to printf(), with
 * these exceptions :
 *  - a level is associated to each log message
 *  - processing stops at the first terminating null byte or newline
 *    character, whichever occurs first
 *
 * This function may safely be called in interrupt context.
 */
int log_msg(unsigned int level, const char *format, ...)
    __attribute__((format(printf, 2, 3)));

int log_vmsg(unsigned int level, const char *format, va_list ap)
    __attribute__((format(printf, 2, 0)));

/*
 * Convenience wrappers.
 */

int log_emerg(const char *format, ...) __attribute__((format(printf, 1, 2)));
int log_alert(const char *format, ...) __attribute__((format(printf, 1, 2)));
int log_crit(const char *format, ...) __attribute__((format(printf, 1, 2)));
int log_err(const char *format, ...) __attribute__((format(printf, 1, 2)));
int log_warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
int log_notice(const char *format, ...) __attribute__((format(printf, 1, 2)));
int log_info(const char *format, ...) __attribute__((format(printf, 1, 2)));
int log_debug(const char *format, ...) __attribute__((format(printf, 1, 2)));

int log_vemerg(const char *format, va_list ap)
    __attribute__((format(printf, 1, 0)));
int log_valert(const char *format, va_list ap)
    __attribute__((format(printf, 1, 0)));
int log_vcrit(const char *format, va_list ap)
    __attribute__((format(printf, 1, 0)));
int log_verr(const char *format, va_list ap)
    __attribute__((format(printf, 1, 0)));
int log_vwarning(const char *format, va_list ap)
    __attribute__((format(printf, 1, 0)));
int log_vnotice(const char *format, va_list ap)
    __attribute__((format(printf, 1, 0)));
int log_vinfo(const char *format, va_list ap)
    __attribute__((format(printf, 1, 0)));
int log_vdebug(const char *format, va_list ap)
    __attribute__((format(printf, 1, 0)));

/*
 * This init operation provides :
 *  - message logging
 *
 * The log thread isn't yet started and messages are merely stored in an
 * internal buffer.
 */
INIT_OP_DECLARE(log_setup);

#endif /* KERN_LOG_H */