2 Copyright (C) 2016 "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)
46 openlog(name, LOG_PERROR, authority ? LOG_AUTH : LOG_USER);
53 static const char *appname;
55 static int appauthority;
57 static const char *prefixes[] = {
68 void vverbose(int level, const char *file, int line, const char *fmt, va_list args)
70 int tty = isatty(fileno(stderr));
72 fprintf(stderr, "%s: ", prefixes[LEVEL(level)] + (tty ? 4 : 0));
73 vfprintf(stderr, fmt, args);
74 if (file != NULL && (!tty || verbosity >5))
75 fprintf(stderr, " [%s:%d]\n", file, line);
77 fprintf(stderr, "\n");
80 void verbose_set_name(const char *name, int authority)
83 appauthority = authority;
88 void verbose(int level, const char *file, int line, const char *fmt, ...)
93 vverbose(level, file, line, fmt, ap);