blob: 7d99a95d0ad490fa73f20ac4f648c6a086b00d17 [file] [log] [blame]
Martin Minarik19e6f262012-06-07 13:08:46 +02001/*
2 * Copyright © 2012 Martin Minarik
3 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Martin Minarik19e6f262012-06-07 13:08:46 +020011 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Martin Minarik19e6f262012-06-07 13:08:46 +020024 */
25
Daniel Stonec228e232013-05-22 18:03:19 +030026#include "config.h"
27
Martin Minarik19e6f262012-06-07 13:08:46 +020028#include <stdio.h>
29#include <stdarg.h>
30#include <stdlib.h>
31#include <string.h>
Martin Minarikeb587652012-06-08 20:59:53 +020032#include <sys/time.h>
Martin Minarik19e6f262012-06-07 13:08:46 +020033#include <time.h>
34
Martin Minarik19e6f262012-06-07 13:08:46 +020035#include <wayland-util.h>
36
Kristian Høgsberg64eca892012-08-01 00:00:57 -040037#include "compositor.h"
Martin Minarik19e6f262012-06-07 13:08:46 +020038
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030039static log_func_t log_handler = 0;
40static log_func_t log_continue_handler = 0;
Derek Foreman6bc33d62015-06-08 11:37:31 -050041
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030042/** Install the log handler
43 *
44 * The given functions will be called to output text as passed to the
45 * \a weston_log and \a weston_log_continue functions.
46 *
47 * \param log The log function. This function will be called when
48 * \a weston_log is called, and should begin a new line,
49 * with user defined line headers, if any.
50 * \param cont The continue log function. This function will be called
51 * when \a weston_log_continue is called, and should append
52 * its output to the current line, without any header or
53 * other content in between.
54 */
55WL_EXPORT void
56weston_log_set_handler(log_func_t log, log_func_t cont)
Martin Minarik19e6f262012-06-07 13:08:46 +020057{
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030058 log_handler = log;
59 log_continue_handler = cont;
Martin Minarik19e6f262012-06-07 13:08:46 +020060}
61
62WL_EXPORT int
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040063weston_vlog(const char *fmt, va_list ap)
64{
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030065 return log_handler(fmt, ap);
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040066}
67
68WL_EXPORT int
Martin Minarik19e6f262012-06-07 13:08:46 +020069weston_log(const char *fmt, ...)
70{
71 int l;
72 va_list argp;
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040073
Martin Minarik19e6f262012-06-07 13:08:46 +020074 va_start(argp, fmt);
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040075 l = weston_vlog(fmt, argp);
Martin Minarik19e6f262012-06-07 13:08:46 +020076 va_end(argp);
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040077
Martin Minarik19e6f262012-06-07 13:08:46 +020078 return l;
79}
80
81WL_EXPORT int
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040082weston_vlog_continue(const char *fmt, va_list argp)
83{
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030084 return log_continue_handler(fmt, argp);
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040085}
86
87WL_EXPORT int
Martin Minarik19e6f262012-06-07 13:08:46 +020088weston_log_continue(const char *fmt, ...)
89{
90 int l;
91 va_list argp;
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040092
Martin Minarik19e6f262012-06-07 13:08:46 +020093 va_start(argp, fmt);
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040094 l = weston_vlog_continue(fmt, argp);
Martin Minarik19e6f262012-06-07 13:08:46 +020095 va_end(argp);
Kristian Høgsberg082d58c2013-06-18 01:00:27 -040096
Martin Minarik19e6f262012-06-07 13:08:46 +020097 return l;
98}