2 * This file is part of the sigrok project.
4 * Copyright (C) 2011 Uwe Hermann <uwe@hermann-uwe.de>
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.
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.
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
21 #include "sigrokdecode.h"
22 #include "sigrokdecode-internal.h"
26 static int srd_loglevel = SRD_LOG_WARN; /* Show errors+warnings per default. */
29 * Set the libsigrokdecode loglevel.
31 * This influences the amount of log messages (debug messages, error messages,
32 * and so on) libsigrokdecode will output. Using SRD_LOG_NONE disables all
35 * @param loglevel The loglevel to set (SRD_LOG_NONE, SRD_LOG_ERR,
36 * SRD_LOG_WARN, SRD_LOG_INFO, SRD_LOG_DBG, or SRD_LOG_SPEW).
37 * @return SRD_OK upon success, SRD_ERR_ARG upon invalid loglevel.
39 int srd_set_loglevel(int loglevel)
41 if (loglevel < SRD_LOG_NONE || loglevel > SRD_LOG_SPEW) {
42 srd_err("log: %s: invalid loglevel %d", __func__, loglevel);
46 srd_loglevel = loglevel;
48 srd_dbg("log: %s: libsigrokdecode loglevel set to %d",
55 * Get the libsigrokdecode loglevel.
57 * @return The currently configured libsigrokdecode loglevel.
59 int srd_get_loglevel(void)
64 static int srd_logv(int loglevel, const char *format, va_list args)
68 /* Only output messages of at least the selected loglevel(s). */
69 if (loglevel > srd_loglevel)
70 return SRD_OK; /* TODO? */
72 ret = vfprintf(stderr, format, args);
73 fprintf(stderr, "\n");
78 int srd_log(int loglevel, const char *format, ...)
83 va_start(args, format);
84 ret = srd_logv(loglevel, format, args);
90 int srd_spew(const char *format, ...)
95 va_start(args, format);
96 ret = srd_logv(SRD_LOG_SPEW, format, args);
102 int srd_dbg(const char *format, ...)
107 va_start(args, format);
108 ret = srd_logv(SRD_LOG_DBG, format, args);
114 int srd_info(const char *format, ...)
119 va_start(args, format);
120 ret = srd_logv(SRD_LOG_INFO, format, args);
126 int srd_warn(const char *format, ...)
131 va_start(args, format);
132 ret = srd_logv(SRD_LOG_WARN, format, args);
138 int srd_err(const char *format, ...)
143 va_start(args, format);
144 ret = srd_logv(SRD_LOG_ERR, format, args);