2015-04-16 13:22:58 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Moritz Grimm <mgrimm@mrsserver.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
|
|
|
#include "attributes.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
#include "cfg.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
static int _log(enum log_levels, const char *, ...)
|
2015-04-16 13:22:58 -04:00
|
|
|
ATTRIBUTE_NONNULL(2)
|
|
|
|
ATTRIBUTE_FORMAT(printf, 2, 3);
|
2015-05-24 03:05:40 -04:00
|
|
|
static int _vlog(enum log_levels, const char *, va_list)
|
2015-04-16 13:22:58 -04:00
|
|
|
ATTRIBUTE_NONNULL(2);
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
static int
|
2015-04-16 13:22:58 -04:00
|
|
|
_log(enum log_levels lvl, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-05-24 03:05:40 -04:00
|
|
|
int ret;
|
2015-04-16 13:22:58 -04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-05-24 03:05:40 -04:00
|
|
|
ret = _vlog(lvl, fmt, ap);
|
2015-04-16 13:22:58 -04:00
|
|
|
va_end(ap);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
static int
|
2015-04-16 13:22:58 -04:00
|
|
|
_vlog(enum log_levels lvl, const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
va_list ap2;
|
|
|
|
int p;
|
|
|
|
|
|
|
|
switch (lvl) {
|
|
|
|
case ALERT:
|
|
|
|
p = LOG_ALERT;
|
|
|
|
break;
|
|
|
|
case ERROR:
|
|
|
|
p = LOG_ERR;
|
|
|
|
break;
|
|
|
|
case WARNING:
|
|
|
|
p = LOG_WARNING;
|
|
|
|
break;
|
|
|
|
case NOTICE:
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_program_verbosity() < 1)
|
2015-05-24 03:05:40 -04:00
|
|
|
return (0);
|
2015-04-16 13:22:58 -04:00
|
|
|
p = LOG_NOTICE;
|
|
|
|
break;
|
|
|
|
case INFO:
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_program_verbosity() < 2)
|
2015-05-24 03:05:40 -04:00
|
|
|
return (0);
|
2015-04-16 13:22:58 -04:00
|
|
|
p = LOG_INFO;
|
|
|
|
break;
|
|
|
|
case DEBUG:
|
|
|
|
default:
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
if (cfg_get_program_verbosity() < 3)
|
2015-05-24 03:05:40 -04:00
|
|
|
return (0);
|
2015-04-16 13:22:58 -04:00
|
|
|
p = LOG_DEBUG;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
va_copy(ap2, ap);
|
|
|
|
vsyslog(p, fmt, ap2);
|
|
|
|
va_end(ap2);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (1);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
int
|
2015-04-16 13:22:58 -04:00
|
|
|
log_init(void)
|
|
|
|
{
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
openlog(cfg_get_program_name(),
|
|
|
|
LOG_PID|LOG_CONS|LOG_NDELAY|LOG_PERROR,
|
2015-04-16 13:22:58 -04:00
|
|
|
LOG_USER);
|
Refactor configuration (work in progress)
* Move -m and -n command line options into the config file
* Restructure configuration file:
- Group into "server", "stream", "media", "metadata", "decoders", and
"encoders"
- Untangle decoder and encoder:
o Decoders match on file extensions and convert to a canonical "internal"
format
o Encoders create one of the supported stream formats, potentially using
different parameters (like bitrate)
- Consistently specify stream format
- Enable reencoding by selecting an encoder
* Architecturally separate configuration file storage from parsing
- Allows for different configuration back-ends in the future, like
YAML, SQL, REST API, ...
* Support roll-back in case of error on (re)load
* Anticipate HTTPS support
2015-05-02 06:48:53 -04:00
|
|
|
return (0);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
log_exit(void)
|
|
|
|
{
|
|
|
|
closelog();
|
|
|
|
}
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
int
|
2015-04-16 13:22:58 -04:00
|
|
|
log_syserr(enum log_levels lvl, int error, const char *pfx)
|
|
|
|
{
|
|
|
|
char errbuf[1024];
|
2015-05-24 03:05:40 -04:00
|
|
|
int ret;
|
2015-04-16 13:22:58 -04:00
|
|
|
|
|
|
|
if (0 != strerror_r(error, errbuf, sizeof(errbuf)))
|
|
|
|
abort();
|
2015-05-24 03:05:40 -04:00
|
|
|
ret = _log(lvl, "%s%s%s",
|
2015-04-16 13:22:58 -04:00
|
|
|
pfx ? pfx : "",
|
|
|
|
pfx ? ": " : "",
|
|
|
|
errbuf);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
int
|
2015-04-16 13:22:58 -04:00
|
|
|
log_alert(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-05-24 03:05:40 -04:00
|
|
|
int ret;
|
2015-04-16 13:22:58 -04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-05-24 03:05:40 -04:00
|
|
|
ret = _vlog(ALERT, fmt, ap);
|
2015-04-16 13:22:58 -04:00
|
|
|
va_end(ap);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
int
|
2015-04-16 13:22:58 -04:00
|
|
|
log_error(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-05-24 03:05:40 -04:00
|
|
|
int ret;
|
2015-04-16 13:22:58 -04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-05-24 03:05:40 -04:00
|
|
|
ret = _vlog(ERROR, fmt, ap);
|
2015-04-16 13:22:58 -04:00
|
|
|
va_end(ap);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
int
|
2015-04-16 13:22:58 -04:00
|
|
|
log_warning(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-05-24 03:05:40 -04:00
|
|
|
int ret;
|
2015-04-16 13:22:58 -04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-05-24 03:05:40 -04:00
|
|
|
ret = _vlog(WARNING, fmt, ap);
|
2015-04-16 13:22:58 -04:00
|
|
|
va_end(ap);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
int
|
2015-04-16 13:22:58 -04:00
|
|
|
log_notice(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-05-24 03:05:40 -04:00
|
|
|
int ret;
|
2015-04-16 13:22:58 -04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-05-24 03:05:40 -04:00
|
|
|
ret = _vlog(NOTICE, fmt, ap);
|
2015-04-16 13:22:58 -04:00
|
|
|
va_end(ap);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
int
|
2015-04-16 13:22:58 -04:00
|
|
|
log_info(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-05-24 03:05:40 -04:00
|
|
|
int ret;
|
2015-04-16 13:22:58 -04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-05-24 03:05:40 -04:00
|
|
|
ret = _vlog(INFO, fmt, ap);
|
2015-04-16 13:22:58 -04:00
|
|
|
va_end(ap);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|
|
|
|
|
2015-05-24 03:05:40 -04:00
|
|
|
int
|
2015-04-16 13:22:58 -04:00
|
|
|
log_debug(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-05-24 03:05:40 -04:00
|
|
|
int ret;
|
2015-04-16 13:22:58 -04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-05-24 03:05:40 -04:00
|
|
|
ret = _vlog(DEBUG, fmt, ap);
|
2015-04-16 13:22:58 -04:00
|
|
|
va_end(ap);
|
2015-05-24 03:05:40 -04:00
|
|
|
|
|
|
|
return (ret);
|
2015-04-16 13:22:58 -04:00
|
|
|
}
|