2 Copyright 2012-2016 David Robillard <http://drobilla.net>
4 Permission to use, copy, modify, and/or distribute this software for any
5 purpose with or without fee is hereby granted, provided that the above
6 copyright notice and this permission notice appear in all copies.
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 @defgroup logger Logger
21 Convenience API for easy logging in plugin code. This API provides simple
22 wrappers for logging from a plugin, which automatically fall back to
23 printing to stderr if host support is unavailabe.
28 #ifndef LV2_ATOM_LOGGER_H
29 #define LV2_ATOM_LOGGER_H
41 Logger convenience API state.
53 Set `map` as the URI map for `logger`.
55 This affects the message type URIDs (Error, Warning, etc) which are passed
56 to the log's print functions.
59 lv2_log_logger_set_map(LV2_Log_Logger
* logger
, LV2_URID_Map
* map
)
62 logger
->Error
= map
->map(map
->handle
, LV2_LOG__Error
);
63 logger
->Note
= map
->map(map
->handle
, LV2_LOG__Note
);
64 logger
->Trace
= map
->map(map
->handle
, LV2_LOG__Trace
);
65 logger
->Warning
= map
->map(map
->handle
, LV2_LOG__Warning
);
67 logger
->Error
= logger
->Note
= logger
->Trace
= logger
->Warning
= 0;
74 URIs will be mapped using `map` and stored, a reference to `map` itself is
75 not held. Both `map` and `log` may be NULL when unsupported by the host,
76 in which case the implementation will fall back to printing to stderr.
79 lv2_log_logger_init(LV2_Log_Logger
* logger
,
84 lv2_log_logger_set_map(logger
, map
);
88 Log a message to the host, or stderr if support is unavailable.
92 lv2_log_vprintf(LV2_Log_Logger
* logger
,
97 if (logger
&& logger
->log
) {
98 return logger
->log
->vprintf(logger
->log
->handle
, type
, fmt
, args
);
100 return vfprintf(stderr
, fmt
, args
);
104 /** Log an error via lv2_log_vprintf(). */
107 lv2_log_error(LV2_Log_Logger
* logger
, const char* fmt
, ...)
111 const int ret
= lv2_log_vprintf(logger
, logger
->Error
, fmt
, args
);
116 /** Log a note via lv2_log_vprintf(). */
119 lv2_log_note(LV2_Log_Logger
* logger
, const char* fmt
, ...)
123 const int ret
= lv2_log_vprintf(logger
, logger
->Note
, fmt
, args
);
128 /** Log a trace via lv2_log_vprintf(). */
131 lv2_log_trace(LV2_Log_Logger
* logger
, const char* fmt
, ...)
135 const int ret
= lv2_log_vprintf(logger
, logger
->Trace
, fmt
, args
);
140 /** Log a warning via lv2_log_vprintf(). */
143 lv2_log_warning(LV2_Log_Logger
* logger
, const char* fmt
, ...)
147 const int ret
= lv2_log_vprintf(logger
, logger
->Warning
, fmt
, args
);
156 #endif /* LV2_LOG_LOGGER_H */