2015-04-10 19:52:35 +02:00
|
|
|
/*
|
|
|
|
This file is part of libcapwap.
|
|
|
|
|
|
|
|
libcapwap 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
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2018-03-05 07:18:02 +01:00
|
|
|
#include "strlist.h"
|
2015-04-10 19:52:35 +02:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
|
2018-03-05 07:18:02 +01:00
|
|
|
const char * cw_log_name = "actube";
|
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
static struct cw_StrListElem prefix[] = {
|
2018-03-05 07:18:02 +01:00
|
|
|
{LOG_DEBUG, "DBG"},
|
|
|
|
{LOG_INFO, "INF" },
|
|
|
|
{LOG_NOTICE, "NOTICE"},
|
|
|
|
{LOG_WARNING, "WARNING"},
|
|
|
|
{LOG_ERR,"ERROR"},
|
|
|
|
{CW_STR_STOP, NULL}
|
|
|
|
};
|
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
static struct cw_StrListElem prefix_color[] = {
|
2018-03-05 07:18:02 +01:00
|
|
|
{LOG_DEBUG, ""},
|
|
|
|
{LOG_INFO, "" },
|
|
|
|
{LOG_NOTICE, ""},
|
|
|
|
{LOG_WARNING, ""},
|
|
|
|
{LOG_ERR,"\033[1;31m"},
|
|
|
|
{CW_STR_STOP, NULL}
|
|
|
|
};
|
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
static struct cw_StrListElem text_color[] = {
|
2018-03-05 07:18:02 +01:00
|
|
|
{LOG_DEBUG, ""},
|
|
|
|
{LOG_INFO, "" },
|
|
|
|
{LOG_NOTICE, ""},
|
|
|
|
{LOG_WARNING, ""},
|
|
|
|
{LOG_ERR,"\033[22m"},
|
|
|
|
{CW_STR_STOP, NULL}
|
|
|
|
};
|
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
static struct cw_StrListElem end_color[] = {
|
2018-03-05 07:18:02 +01:00
|
|
|
{LOG_DEBUG, ""},
|
|
|
|
{LOG_INFO, "" },
|
|
|
|
{LOG_NOTICE, ""},
|
|
|
|
{LOG_WARNING, ""},
|
|
|
|
{LOG_ERR,"\033[22;39m"},
|
|
|
|
{CW_STR_STOP, NULL}
|
|
|
|
};
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
struct cw_LogWriter * cw_log_writers[] = {
|
2018-03-05 07:18:02 +01:00
|
|
|
&cw_log_syslog_writer,
|
|
|
|
&cw_log_console_writer,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void cw_log(int prio, const char *format, ...)
|
2015-04-10 19:52:35 +02:00
|
|
|
{
|
2018-03-05 07:18:02 +01:00
|
|
|
va_list args;
|
|
|
|
char fbuf[1024];
|
|
|
|
int i;
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
for (i=0; cw_log_writers[i]; i++){
|
2018-03-05 07:18:02 +01:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
if (cw_log_writers[i]->colored){
|
2018-03-05 07:18:02 +01:00
|
|
|
sprintf(fbuf, "%s%s%s: %s%s",
|
|
|
|
cw_strlist_get_str(prefix_color,prio),
|
|
|
|
cw_strlist_get_str(prefix,prio),
|
|
|
|
cw_strlist_get_str(text_color,prio),
|
|
|
|
format,
|
|
|
|
cw_strlist_get_str(end_color,prio)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
sprintf(fbuf, "%s: %s",
|
|
|
|
cw_strlist_get_str(prefix,prio),
|
|
|
|
format
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
va_start(args, format);
|
2018-03-18 21:48:34 +01:00
|
|
|
cw_log_writers[i]->write(prio,fbuf,args,cw_log_writers[i]);
|
2018-03-05 07:18:02 +01:00
|
|
|
va_end(args);
|
2015-04-10 19:52:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-05 07:18:02 +01:00
|
|
|
void cw_log_init(){
|
|
|
|
int i;
|
2018-03-18 21:48:34 +01:00
|
|
|
for (i=0; cw_log_writers[i]; i++){
|
|
|
|
cw_log_writers[i]->open();
|
2015-04-10 19:52:35 +02:00
|
|
|
}
|
|
|
|
}
|