Introduced colored loggin.

FossilOrigin-Name: 55fc8222563fd1a327c866a216bf590a28190fed0d9509ac35667b349637619b
This commit is contained in:
7u83@mail.ru 2015-04-10 17:51:56 +00:00
parent 1f278d01f3
commit 1e7d8a9cad
11 changed files with 161 additions and 177 deletions

View File

@ -34,10 +34,10 @@ SOCKOBJS=sock_create.o sock_copyaddr.o sock_strtoaddr.o sock_cmpaddr.o sock_addr
sock_get_primary_if.o \
sock_receive.o \
LOGOBJS=cw_log.o \
LOGOBJS=log.o \
log_syslog.o \
log_file.o \
cw_log_debug.o \
cw_log_tofile.o \
cw_log_tosyslog.o \
cw_log_str2dbglevel.o \
cw_dbg_elem.o
@ -106,12 +106,6 @@ CAPWAPOBJS= \
cwmsg_addelem_maximum_message_length.o \
cwmsg_addelem_image_identifier.o \
cwmsg_send.o \
cwsend_unknow_response.o \
cw_send_configuration_update_response.o \
cwsend_echo_request.o \
cw_send_echo_response.o \
cw_handle_echo_request.o \
cwsend_conf_status_response.o\
wtpinfo.o \
aciplist.o \
acinfo.o \
@ -151,7 +145,13 @@ CAPWAPOBJS= \
format.o \
# cw_readmsg_configuration_status_response.o \
# cwsend_unknow_response.o \
cw_send_configuration_update_response.o \
cwsend_echo_request.o \
cw_send_echo_response.o \
cw_handle_echo_request.o \
cwsend_conf_status_response.o\
cw_readmsg_configuration_status_response.o \
cw_readmsg_configuration_status_request.o \
cw_readelem_maximum_message_length.o \
cw_readelem_result_code.o\

View File

@ -1,26 +0,0 @@
/*
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 <stdarg.h>
#include "log.h"
void (*cw_log_cb)(int level,const char * fromat, ...) = CW_LOG_DEFAULT_LOG;
const char * cw_log_name = "cw";

View File

@ -64,97 +64,6 @@ void cw_log_dbg_(int level, const char *file, int line, const char *format, ...)
void cw_log_dbg_dmp_(int level, const char *file, int line,
const uint8_t * data, int len, const char *format, ...)
{
if (!(level & cw_dbg_opt_level))
return;
int maxtlen = 2048;
int i;
int rowlen = CW_LOG_DUMP_ROW_LEN;
int rows = len / rowlen;
int tlen = 0;
int md;
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP)
md = 2;
else
md = 1;
char *dst = malloc(md * (len * 3 + (rows * 2) + 8 + maxtlen));
if (!dst)
return;
if (format != NULL) {
va_list args;
va_start(args, format);
tlen = vsnprintf(dst, maxtlen, format, args);
va_end(args);
}
if (len % CW_LOG_DUMP_ROW_LEN)
rows++;
char *pdst = dst + tlen;
sprintf(pdst, "\n\t");
pdst += 2;
char asc_buffer[128];
char *ascdst = asc_buffer;
for (i = 0; i < len; i++) {
sprintf(pdst, "%02X ", data[i] & 0xff);
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
int c = data[i] & 0xff;
if (c < 0x20 || c > 0x80)
c = '.';
*ascdst = c;
ascdst++;
}
pdst += 3;
if ((i + 1) % rowlen == 0) {
int l;
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
*ascdst = 0;
l = sprintf(pdst, " | %s\n\t", asc_buffer);
ascdst = asc_buffer;
} else {
l = sprintf(pdst, "\n\t");
}
pdst += l;
}
}
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
*ascdst = 0;
if (strlen(asc_buffer))
pdst += sprintf(pdst, " | %s", asc_buffer);
}
if (cw_dbg_opt_detail & DBG_DETAIL_LINE_NUMBERS)
cw_log(LOG_DEBUG, "%s:%d: %s", file, line, dst);
else
cw_log(LOG_DEBUG, dst);
free(dst);
return;
}

View File

@ -68,3 +68,95 @@ void cw_dbg_packet(struct conn *conn, uint8_t * packet, int len)
}
void cw_log_dbg_dmp_(int level, const char *file, int line,
const uint8_t * data, int len, const char *format, ...)
{
if (!(level & cw_dbg_opt_level))
return;
int maxtlen = 2048;
int i;
int rowlen = CW_LOG_DUMP_ROW_LEN;
int rows = len / rowlen;
int tlen = 0;
int md;
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP)
md = 2;
else
md = 1;
char *dst = malloc(md * (len * 3 + (rows * 2) + 8 + maxtlen));
if (!dst)
return;
if (format != NULL) {
va_list args;
va_start(args, format);
tlen = vsnprintf(dst, maxtlen, format, args);
va_end(args);
}
if (len % CW_LOG_DUMP_ROW_LEN)
rows++;
char *pdst = dst + tlen;
sprintf(pdst, "\n\t");
pdst += 2;
char asc_buffer[128];
char *ascdst = asc_buffer;
for (i = 0; i < len; i++) {
sprintf(pdst, "%02X ", data[i] & 0xff);
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
int c = data[i] & 0xff;
if (c < 0x20 || c > 0x80)
c = '.';
*ascdst = c;
ascdst++;
}
pdst += 3;
if ((i + 1) % rowlen == 0) {
int l;
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
*ascdst = 0;
l = sprintf(pdst, " | %s\n\t", asc_buffer);
ascdst = asc_buffer;
} else {
l = sprintf(pdst, "\n\t");
}
pdst += l;
}
}
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
*ascdst = 0;
if (strlen(asc_buffer))
pdst += sprintf(pdst, " | %s", asc_buffer);
}
if (cw_dbg_opt_detail & DBG_DETAIL_LINE_NUMBERS)
cw_log(LOG_DEBUG, "%s:%d: %s", file, line, dst);
else
cw_log(LOG_DEBUG, dst);
free(dst);
return;
}

View File

@ -3,6 +3,15 @@
#include "conn.h"
#ifndef CW_LOG_DUMP_ROW_LEN
#define CW_LOG_DUMP_ROW_LEN 32
#endif
#ifndef CW_LOG_DUMP_ROW_TAB_LEN
#define CW_LOG_DUMP_ROW_TAB_LEN 8
#endif
void cw_dbg_elem_(struct conn * conn, int msg, int msgelem, const uint8_t * msgbuf, int len);
void cw_dbg_missing_mand(int level,struct conn *conn,cw_action_in_t ** ml,int n,cw_action_in_t *a);
void cw_dbg_packet(struct conn *conn, uint8_t * packet, int len);

View File

@ -32,6 +32,19 @@
#define LOG_ERROR LOG_ERR
#endif
#ifndef CW_LOG_DEFAULT_LOG
#define CW_LOG_DEFAULT_LOG cw_log_file
#endif
#ifndef CW_LOG_DEFAULT_VLOG
#define CW_LOG_DEFAULT_VLOG cw_log_vfile
#endif
/**
* @defgroup DebugOptions Dbug Options
* @{
@ -78,17 +91,7 @@
/**@}*/
#ifndef CW_LOG_DUMP_ROW_LEN
#define CW_LOG_DUMP_ROW_LEN 32
#endif
#ifndef CW_LOG_DUMP_ROW_TAB_LEN
#define CW_LOG_DUMP_ROW_TAB_LEN 8
#endif
#ifndef CW_LOG_DEFAULT_LOG
#define CW_LOG_DEFAULT_LOG cw_log_tosyslog
#endif
extern void cw_log_dbg_(int type, const char *file, int line, const char *fromat, ...);
@ -103,7 +106,7 @@ extern int cw_dbg_opt_level;
#ifdef WITH_CW_LOG
#define cw_log(level,...) cw_log_cb(level,__VA_ARGS__)
#define cw_log(level,...) cw_log_colored(level,__VA_ARGS__)
#else
#define cw_log(...)
#endif
@ -129,14 +132,27 @@ extern int cw_dbg_opt_level;
#endif
extern void (*cw_log_cb) (int level, const char *fromat, ...);
extern void (*cw_log_debug_cb) (int type, const char *format, ...);
extern void (*cw_vlog_cb) (int level, const char *fromat, va_list args);
extern void (*cw_log_debug_cbs[]) (const char *fromat, ...);
/* Syslog functins */
extern void cw_log_syslog(int level, const char *format, ...);
extern void cw_log_vsyslog(int level,const char * format, va_list args);
/* Log to File functions */
void cw_log_vfile(int level,const char * format, va_list args);
void cw_log_file(int level,const char *format, ...);
void cw_log_colored(int level, const char *format, ...);
//extern void (*cw_log_debug_cb) (int type, const char *format, ...);
//extern void (*cw_log_debug_cbs[]) (const char *fromat, ...);
extern int cw_log_debug_dump_(int level, const uint8_t * data, int len,
const char *format, ...);
extern void cw_vlog_(int level, const char *format, va_list args);
extern void cw_log_tosyslog(int level, const char *format, ...);
extern void cw_log_tofile(int level, const char *format, ...);
extern void cw_dbg_msgelem_(int msg, int msgelem, const uint8_t * msgbuf, int len);

View File

@ -8,27 +8,30 @@ int cw_log_file_flags = LOG_PERROR;
char * cw_log_filename = NULL;
void cw_vlog_tofile_(int level,const char * format, va_list args)
void cw_log_vfile(int level,const char * format, va_list args)
{
switch(level){
/* switch(level){
case LOG_DEBUG:
printf("DEBUG:");
printf("DBG:");
break;
case LOG_INFO:
printf("INFO:");
break;
case LOG_ERR:
printf("ERROR:");
break;
}
*/
vprintf(format,args);
printf("\n");
}
void cw_log_tofile(int level,const char *format, ...)
void cw_log_file(int level,const char *format, ...)
{
va_list args;
va_start(args, format);
// cw_vlog_(level,format,args);
cw_vlog_tofile_(level,format,args);
cw_log_vfile(level,format,args);
va_end(args);
closelog();
}

View File

@ -19,17 +19,17 @@
#include "log.h"
void cw_vlog_(int level,const char * format, va_list args)
void cw_log_vsyslog(int level,const char * format, va_list args)
{
openlog (cw_log_name, LOG_PERROR | LOG_CONS | LOG_PID | LOG_NDELAY, LOG_DEBUG);
vsyslog(level,format,args);
}
void cw_log_tosyslog(int level,const char *format, ...)
void cw_log_syslog(int level,const char *format, ...)
{
va_list args;
va_start(args, format);
cw_vlog_(level,format,args);
cw_log_vsyslog(level,format,args);
va_end(args);
closelog();
}

View File

@ -1,23 +0,0 @@
#include "wtpinfo.h"
#include "capwap.h"
#include "cw_log.h"
int wtpinfo_readelem_discovery_type(struct wtpinfo * wtpinfo, int type, uint8_t * msgelem, int len)
{
if (type != CW_ELEM_DISCOVERY_TYPE)
return 0;
if (len!=1){
cw_dbg(DBG_MSG_ERR,"Discarding WTP_DISCOVERY_TYPE msgelem, wrong size, type=%d,len=%d",type,len);
return 1;
}
wtpinfo->discovery_type=*msgelem;
return 1;
}

View File

@ -170,7 +170,9 @@ int run_join(struct conn * conn)
}
if (rc != 0 && rc != 2) {
cw_log(LOG_ERR,"Join to %s was not successful.",sock_addr2str(&conn->addr));
cw_log(LOG_ERR,"Can't Join AC at %s, AC returned code: %d - %s.",
sock_addr2str(&conn->addr),
rc,cw_strresult(rc));
return 0;
}

View File

@ -75,6 +75,8 @@ int main()
cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube");
cw_log(LOG_ERR,"Entetrente");
discovery();
join();