2 * This file is part of the libjaylink project.
4 * Copyright (C) 2014-2015 Marc Schink <jaylink-dev@marcschink.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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "libjaylink.h"
24 #include "libjaylink-internal.h"
33 * Set the libjaylink log level.
35 * @param[in,out] ctx libjaylink context.
36 * @param[in] level Log level to set. See #jaylink_log_level for valid values.
38 * @retval JAYLINK_OK Success.
39 * @retval JAYLINK_ERR_ARG Invalid arguments.
41 JAYLINK_API
int jaylink_log_set_level(struct jaylink_context
*ctx
, int level
)
44 return JAYLINK_ERR_ARG
;
46 if (level
< JAYLINK_LOG_LEVEL_NONE
|| level
> JAYLINK_LOG_LEVEL_DEBUG
)
47 return JAYLINK_ERR_ARG
;
49 ctx
->log_level
= level
;
55 * Get the libjaylink log level.
57 * @param[in] ctx libjaylink context.
59 * @return The current log level on success, or a negative error code
60 * on failure. See #jaylink_log_level for a description of each
61 * individual log level.
63 JAYLINK_API
int jaylink_log_get_level(const struct jaylink_context
*ctx
)
66 return JAYLINK_ERR_ARG
;
68 return ctx
->log_level
;
72 static void log_vprintf(struct jaylink_context
*ctx
, int level
,
73 const char *format
, va_list args
)
76 * Filter out messages with higher verbosity than the verbosity of the
79 if (level
> ctx
->log_level
)
82 fprintf(stderr
, "jaylink: ");
83 vfprintf(stderr
, format
, args
);
84 fprintf(stderr
, "\n");
88 JAYLINK_PRIV
void log_err(struct jaylink_context
*ctx
, const char *format
, ...)
95 va_start(args
, format
);
96 log_vprintf(ctx
, JAYLINK_LOG_LEVEL_ERROR
, format
, args
);
101 JAYLINK_PRIV
void log_warn(struct jaylink_context
*ctx
, const char *format
, ...)
108 va_start(args
, format
);
109 log_vprintf(ctx
, JAYLINK_LOG_LEVEL_WARNING
, format
, args
);
114 JAYLINK_PRIV
void log_info(struct jaylink_context
*ctx
, const char *format
, ...)
121 va_start(args
, format
);
122 log_vprintf(ctx
, JAYLINK_LOG_LEVEL_INFO
, format
, args
);
127 JAYLINK_PRIV
void log_dbg(struct jaylink_context
*ctx
, const char *format
, ...)
134 va_start(args
, format
);
135 log_vprintf(ctx
, JAYLINK_LOG_LEVEL_DEBUG
, format
, args
);