2 Copyright (C) 2016-2019 "IoT.bzh"
4 author: José Bollo <jose.bollo@iot.bzh>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
26 #define LEVEL(x) ((x) < 0 ? 0 : (x) > 7 ? 7 : (x))
28 #if defined(VERBOSE_WITH_SYSLOG)
32 void vverbose(int level, const char *file, int line, const char *fmt, va_list args)
36 if (file == NULL || vasprintf(&p, fmt, args) < 0)
37 vsyslog(level, fmt, args);
39 syslog(LEVEL(level), "%s [%s:%d]", p, file, line);
44 void verbose_set_name(const char *name, int authority)
47 openlog(name, LOG_PERROR, authority ? LOG_AUTH : LOG_USER);
59 static int appauthority;
61 static const char *prefixes[] = {
72 void vverbose(int level, const char *file, int line, const char *fmt, va_list args)
75 int tty = isatty(fileno(stderr));
78 fprintf(stderr, "%s: ", prefixes[LEVEL(level)] + (tty ? 4 : 0));
79 vfprintf(stderr, fmt, args);
80 if (file != NULL && (!tty || verbosity >5))
81 fprintf(stderr, " [%s:%d]\n", file, line);
83 fprintf(stderr, "\n");
86 void verbose_set_name(const char *name, int authority)
89 appname = name ? strdup(name) : NULL;
90 appauthority = authority;
95 void verbose(int level, const char *file, int line, const char *fmt, ...)
100 vverbose(level, file, line, fmt, ap);