2017-07-12 00:56:08 +02:00
|
|
|
/** Logging and debugging routines
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#include <errno.h>
|
2017-07-12 00:58:37 +02:00
|
|
|
#include <unistd.h>
|
2017-09-16 11:32:04 +02:00
|
|
|
#include <syslog.h>
|
2017-07-12 00:56:08 +02:00
|
|
|
|
2017-12-09 02:19:28 +08:00
|
|
|
#include <villas/utils.h>
|
|
|
|
#include <villas/log.h>
|
2017-07-12 00:56:08 +02:00
|
|
|
|
|
|
|
void debug(long class, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2017-08-20 10:51:41 +02:00
|
|
|
struct log *l = global_log;
|
2017-07-12 00:56:08 +02:00
|
|
|
|
|
|
|
int lvl = class & 0xFF;
|
|
|
|
int fac = class & ~0xFF;
|
|
|
|
|
|
|
|
if (((fac == 0) || (fac & l->facilities)) && (lvl <= l->level)) {
|
|
|
|
va_start(ap, fmt);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
log_vprint(l, LOG_LVL_DEBUG, fmt, ap);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
|
|
|
if (l->syslog)
|
|
|
|
syslog(LOG_DEBUG, fmt, ap);
|
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void info(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2017-08-20 10:51:41 +02:00
|
|
|
struct log *l = global_log;
|
2017-07-12 00:56:08 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
log_vprint(l, LOG_LVL_INFO, fmt, ap);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
|
|
|
if (l->syslog)
|
|
|
|
syslog(LOG_INFO, fmt, ap);
|
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void warn(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2017-08-20 10:51:41 +02:00
|
|
|
struct log *l = global_log;
|
2017-07-12 00:56:08 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
log_vprint(l, LOG_LVL_WARN, fmt, ap);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
|
|
|
if (l->syslog)
|
|
|
|
syslog(LOG_WARNING, fmt, ap);
|
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void stats(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2017-08-20 10:51:41 +02:00
|
|
|
struct log *l = global_log;
|
2017-07-12 00:56:08 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
log_vprint(l, LOG_LVL_STATS, fmt, ap);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
|
|
|
if (l->syslog)
|
|
|
|
syslog(LOG_INFO, fmt, ap);
|
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void error(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2017-08-20 10:51:41 +02:00
|
|
|
struct log *l = global_log;
|
2017-07-12 00:56:08 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
log_vprint(l, LOG_LVL_ERROR, fmt, ap);
|
2017-09-16 11:32:04 +02:00
|
|
|
|
|
|
|
if (l->syslog)
|
|
|
|
syslog(LOG_ERR, fmt, ap);
|
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
va_end(ap);
|
|
|
|
|
2017-07-12 00:58:37 +02:00
|
|
|
killme(SIGABRT);
|
|
|
|
pause();
|
2017-07-12 00:56:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void serror(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *buf = NULL;
|
|
|
|
|
2017-08-20 10:51:41 +02:00
|
|
|
struct log *l = global_log;
|
2017-07-12 00:56:08 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vstrcatf(&buf, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
log_print(l, LOG_LVL_ERROR, "%s: %m (%u)", buf, errno);
|
|
|
|
|
2017-09-16 11:32:04 +02:00
|
|
|
if (l->syslog)
|
|
|
|
syslog(LOG_ERR, "%s: %m (%u)", buf, errno);
|
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
free(buf);
|
2017-07-12 00:58:37 +02:00
|
|
|
|
|
|
|
killme(SIGABRT);
|
|
|
|
pause();
|
2017-07-24 19:33:35 +02:00
|
|
|
}
|