]> sigrok.org Git - libsigrok.git/blame - log.c
libsigrok: Introduce sr_dbg/sr_info/sr_warn/sr_err.
[libsigrok.git] / log.c
CommitLineData
b08024a8
UH
1/*
2 * This file is part of the sigrok project.
3 *
4 * Copyright (C) 2011 Uwe Hermann <uwe@hermann-uwe.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdarg.h>
22#include <stdio.h>
23#include <sigrok.h>
24#include <sigrok-internal.h>
25
26static int sr_logv(int loglevel, const char *format, va_list args)
27{
28 int ret;
29
30 /* Avoid compiler warnings. */
31 loglevel = loglevel;
32
33 ret = vfprintf(stderr, format, args);
34 fprintf(stderr, "\n");
35
36 return ret;
37}
38
39int sr_log(int loglevel, const char *format, ...)
40{
41 int ret;
42 va_list args;
43
44 va_start(args, format);
45 ret = sr_logv(loglevel, format, args);
46 va_end(args);
47
48 return ret;
49}
50
51int sr_dbg(const char *format, ...)
52{
53 int ret;
54 va_list args;
55
56 va_start(args, format);
57 ret = sr_logv(SR_LOG_DBG, format, args);
58 va_end(args);
59
60 return ret;
61}
62
63int sr_info(const char *format, ...)
64{
65 int ret;
66 va_list args;
67
68 va_start(args, format);
69 ret = sr_logv(SR_LOG_INFO, format, args);
70 va_end(args);
71
72 return ret;
73}
74
75int sr_warn(const char *format, ...)
76{
77 int ret;
78 va_list args;
79
80 va_start(args, format);
81 ret = sr_logv(SR_LOG_WARN, format, args);
82 va_end(args);
83
84 return ret;
85}
86
87int sr_err(const char *format, ...)
88{
89 int ret;
90 va_list args;
91
92 va_start(args, format);
93 ret = sr_logv(SR_LOG_ERR, format, args);
94 va_end(args);
95
96 return ret;
97}