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 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, see <http://www.gnu.org/licenses/>.
27 #include "libjaylink.h"
28 #include "libjaylink-internal.h"
37 * Set the libjaylink log level.
39 * @param[in,out] ctx libjaylink context.
40 * @param[in] level Log level to set.
42 * @retval JAYLINK_OK Success.
43 * @retval JAYLINK_ERR_ARG Invalid arguments.
47 JAYLINK_API
int jaylink_log_set_level(struct jaylink_context
*ctx
,
48 enum jaylink_log_level level
)
51 return JAYLINK_ERR_ARG
;
53 if (level
> JAYLINK_LOG_LEVEL_DEBUG_IO
)
54 return JAYLINK_ERR_ARG
;
56 ctx
->log_level
= level
;
62 * Get the libjaylink log level.
64 * @param[in] ctx libjaylink context.
65 * @param[out] level Log level on success, and undefined on failure.
67 * @retval JAYLINK_OK Success.
68 * @retval JAYLINK_ERR_ARG Invalid arguments.
72 JAYLINK_API
int jaylink_log_get_level(const struct jaylink_context
*ctx
,
73 enum jaylink_log_level
*level
)
76 return JAYLINK_ERR_ARG
;
78 *level
= ctx
->log_level
;
84 * Set the libjaylink log callback function.
86 * @param[in,out] ctx libjaylink context.
87 * @param[in] callback Callback function to use, or NULL to use the default log
89 * @param[in] user_data User data to be passed to the callback function.
91 * @retval JAYLINK_OK Success.
92 * @retval JAYLINK_ERR_ARG Invalid arguments.
96 JAYLINK_API
int jaylink_log_set_callback(struct jaylink_context
*ctx
,
97 jaylink_log_callback callback
, void *user_data
)
100 return JAYLINK_ERR_ARG
;
103 ctx
->log_callback
= callback
;
104 ctx
->log_callback_data
= user_data
;
106 ctx
->log_callback
= &log_vprintf
;
107 ctx
->log_callback_data
= NULL
;
114 * Set the libjaylink log domain.
116 * The log domain is a string which is used as prefix for all log messages to
117 * differentiate them from messages of other libraries.
119 * The maximum length of the log domain is #JAYLINK_LOG_DOMAIN_MAX_LENGTH
120 * bytes, excluding the trailing null-terminator. A log domain which exceeds
121 * this length will be silently truncated.
123 * @param[in,out] ctx libjaylink context.
124 * @param[in] domain Log domain to use. To set the default log domain, use
125 * #JAYLINK_LOG_DOMAIN_DEFAULT.
127 * @retval JAYLINK_OK Success.
128 * @retval JAYLINK_ERR_ARG Invalid arguments.
129 * @retval JAYLINK_ERR Other error conditions.
133 JAYLINK_API
int jaylink_log_set_domain(struct jaylink_context
*ctx
,
139 return JAYLINK_ERR_ARG
;
141 ret
= snprintf(ctx
->log_domain
, JAYLINK_LOG_DOMAIN_MAX_LENGTH
+ 1,
151 * Get the libjaylink log domain.
153 * @param[in] ctx libjaylink context.
155 * @return A string which contains the current log domain on success, or NULL
156 * on failure. The string is null-terminated and must not be free'd by
161 JAYLINK_API
const char *jaylink_log_get_domain(
162 const struct jaylink_context
*ctx
)
167 return ctx
->log_domain
;
171 JAYLINK_PRIV
int log_vprintf(const struct jaylink_context
*ctx
,
172 enum jaylink_log_level level
, const char *format
, va_list args
,
178 * Filter out messages with higher verbosity than the verbosity of the
181 if (level
> ctx
->log_level
)
184 if (ctx
->log_domain
[0] != '\0')
185 fprintf(stderr
, "%s", ctx
->log_domain
);
187 vfprintf(stderr
, format
, args
);
188 fprintf(stderr
, "\n");
194 JAYLINK_PRIV
void log_err(const struct jaylink_context
*ctx
,
195 const char *format
, ...)
202 va_start(args
, format
);
203 ctx
->log_callback(ctx
, JAYLINK_LOG_LEVEL_ERROR
, format
, args
,
204 ctx
->log_callback_data
);
209 JAYLINK_PRIV
void log_warn(const struct jaylink_context
*ctx
,
210 const char *format
, ...)
217 va_start(args
, format
);
218 ctx
->log_callback(ctx
, JAYLINK_LOG_LEVEL_WARNING
, format
, args
,
219 ctx
->log_callback_data
);
224 JAYLINK_PRIV
void log_info(const struct jaylink_context
*ctx
,
225 const char *format
, ...)
232 va_start(args
, format
);
233 ctx
->log_callback(ctx
, JAYLINK_LOG_LEVEL_INFO
, format
, args
,
234 ctx
->log_callback_data
);
239 JAYLINK_PRIV
void log_dbg(const struct jaylink_context
*ctx
,
240 const char *format
, ...)
247 va_start(args
, format
);
248 ctx
->log_callback(ctx
, JAYLINK_LOG_LEVEL_DEBUG
, format
, args
,
249 ctx
->log_callback_data
);
254 JAYLINK_PRIV
void log_dbgio(const struct jaylink_context
*ctx
,
255 const char *format
, ...)
262 va_start(args
, format
);
263 ctx
->log_callback(ctx
, JAYLINK_LOG_LEVEL_DEBUG_IO
, format
, args
,
264 ctx
->log_callback_data
);