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("Invalid loglevel %d.", loglevel);
46 srd_loglevel = loglevel;
48 srd_dbg("srd: loglevel set to %d", loglevel);
54 * Get the libsigrokdecode loglevel.
56 * @return The currently configured libsigrokdecode loglevel.
58 int srd_get_loglevel(void)
63 static int srd_logv(int loglevel, const char *format, va_list args)
67 /* Only output messages of at least the selected loglevel(s). */
68 if (loglevel > srd_loglevel)
69 return SRD_OK; /* TODO? */
71 ret = vfprintf(stderr, format, args);
72 fprintf(stderr, "\n");
77 int srd_log(int loglevel, const char *format, ...)
82 va_start(args, format);
83 ret = srd_logv(loglevel, format, args);
89 int srd_spew(const char *format, ...)
94 va_start(args, format);
95 ret = srd_logv(SRD_LOG_SPEW, format, args);
101 int srd_dbg(const char *format, ...)
106 va_start(args, format);
107 ret = srd_logv(SRD_LOG_DBG, format, args);
113 int srd_info(const char *format, ...)
118 va_start(args, format);
119 ret = srd_logv(SRD_LOG_INFO, format, args);
125 int srd_warn(const char *format, ...)
130 va_start(args, format);
131 ret = srd_logv(SRD_LOG_WARN, format, args);
137 int srd_err(const char *format, ...)
142 va_start(args, format);
143 ret = srd_logv(SRD_LOG_ERR, format, args);