Commit 0a773aee authored by Marc Ariberti's avatar Marc Ariberti

* Make the logs wrap to 80 characters

* Change a bit the way the 'method' variable is used, it is
now a bit-mask to know which are the outputs :
LOG_FILE or LOG_SCREEN are the two options implemented

* the bit-mask change is completely transparent with old config file,
the values are the same, only the method to determine is changed
parent d5db9889
......@@ -3,7 +3,7 @@
* Generate a parser for the config file
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: config.fl,v 1.19 2001/04/30 14:58:54 gunther Exp $
* $Id: config.fl,v 1.20 2001/05/15 22:57:23 marcari Exp $
*
* Authors: Brieuc Jeunhomme <bbp@via.ecp.fr>
*
......@@ -128,7 +128,7 @@ logfile{BL}{NONBLANK}+ {
logmethod{BL}{INT} {
if (cfg->logmethod)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : logemthod has "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : logmethod has "\
"already been defined",filename,line_num);
return VS_R_PARSE;
}
......
# vlanserver's configuration file
logmethod 3 # 3 means File and Screen
# 2 means Screen only
# 1 means File only
logmethod 3 # 2 means Screen
# 1 means File
# 0 means none
# add the numbers to have more than one output
logfile test.log # the name of the file where to log
nchannels 7 # the number of channels, they will range from 0 to 6
......
......@@ -3,10 +3,11 @@
* Print a log to a file or to screen
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: logger.c,v 1.17 2001/04/29 03:41:49 nitrox Exp $
* $Id: logger.c,v 1.18 2001/05/15 22:57:23 marcari Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
*
* Marc Ariberti <marcari@via.ecp.fr>
*
* 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 2 of the License, or
......@@ -45,12 +46,21 @@ static pthread_mutex_t ptmLogScreen;
/*****************************************************************************
* VS_log_File : Write a log inside fdLogfile
*****************************************************************************/
static void VS_log_File(LOG_LEVELS level,\
LOG_MODULES module,\
char* format,\
static void VS_log_File(LOG_LEVELS level,
LOG_MODULES module,
char* format,
va_list ap)
{
char MsgBuff[LOGBUFF_MAXSIZE+20];
char MsgBuff[LOGBUFF_MAXSIZE]; /* buffer which will contain
the message wanted to be displayed */
char LineBuff[LOGBUFF_LINESIZE]; /* line currently displayed */
char HeaderBuff[34+20]; /* header of the message + color */
char FooterBuff[20]; /* footer of the message + end color */
int MessagePosition;
int MessageLength;
time_t MsgTime;
struct tm * ptmTime;
......@@ -61,7 +71,7 @@ static void VS_log_File(LOG_LEVELS level,\
/* Record the time */
time(&MsgTime);
ptmTime=localtime(&MsgTime);
sprintf(MsgBuff, "%02i/%02i %02i:%02i:%02i ", ptmTime->tm_mday,
sprintf(HeaderBuff, "%02i/%02i %02i:%02i:%02i ", ptmTime->tm_mday,
ptmTime->tm_mon+1, ptmTime->tm_hour,
ptmTime->tm_min, ptmTime->tm_sec);
......@@ -71,61 +81,77 @@ static void VS_log_File(LOG_LEVELS level,\
switch (module)
{
case SNMP:
sprintf(MsgBuff+strlen(MsgBuff), "[SNMP : ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[SNMP : ");
break;
case SERVER:
sprintf(MsgBuff+strlen(MsgBuff), "[SERVER: ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[SERVER: ");
break;
case DB:
sprintf(MsgBuff+strlen(MsgBuff), "[DB : ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[DB : ");
break;
case CFG:
sprintf(MsgBuff+strlen(MsgBuff), "[CFG : ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[CFG : ");
break;
case IF:
sprintf(MsgBuff+strlen(MsgBuff), "[IF : ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[IF : ");
break;
case TELNET:
sprintf(MsgBuff+strlen(MsgBuff), "[TELNET: ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[TELNET: ");
break;
case LOGGER:
sprintf(MsgBuff+strlen(MsgBuff), "[LOGGER: ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[LOGGER: ");
break;
}
/* Determinate the error level */
switch (level)
{
case LOGDEBUG:
sprintf(MsgBuff+strlen(MsgBuff), "debug ] ");
sprintf(HeaderBuff+strlen(HeaderBuff), "debug ] ");
break;
case LOGINFO:
sprintf(MsgBuff+strlen(MsgBuff), "info ] ");
sprintf(HeaderBuff+strlen(HeaderBuff), "info ] ");
break;
case LOGWARNING:
sprintf(MsgBuff+strlen(MsgBuff), "Warning ] ");
sprintf(HeaderBuff+strlen(HeaderBuff), "Warning ] ");
break;
case LOGFATAL:
sprintf(MsgBuff+strlen(MsgBuff), "FATAL ] ");
{
sprintf(HeaderBuff+strlen(HeaderBuff), "FATAL ] ");
break;
}
case LOGERROR:
sprintf(MsgBuff+strlen(MsgBuff), "ERROR ] ");
{
sprintf(HeaderBuff+strlen(HeaderBuff), "ERROR ] ");
break;
}
}
/* XXX No error checking ! What length is the message ? */
vsnprintf(MsgBuff+strlen(MsgBuff), LOGBUFF_MAXSIZE, format, ap);
sprintf(MsgBuff+strlen(MsgBuff), "\n");
vsnprintf(MsgBuff, LOGBUFF_MAXSIZE, format, ap);
sprintf(FooterBuff,"\n");
pthread_mutex_lock(&ptmLogFile);
fprintf(fdLogFile, MsgBuff);
fputs(HeaderBuff, fdLogFile);
MessageLength = strlen(MsgBuff);
MessagePosition = 0;
while ( (MessageLength-MessagePosition) > LOGBUFF_LINESIZE )
{
snprintf( LineBuff, LOGBUFF_LINESIZE+1, MsgBuff + MessagePosition );
fputs( LineBuff, fdLogFile );
fputs( "\n ", fdLogFile );
MessagePosition += LOGBUFF_LINESIZE;
}
fputs( MsgBuff + MessagePosition, fdLogFile);
fputs(FooterBuff, fdLogFile);
fflush(fdLogFile);
pthread_mutex_unlock(&ptmLogFile);
......@@ -139,12 +165,20 @@ static void VS_log_File(LOG_LEVELS level,\
/*****************************************************************************
* Write a log on stderr
*****************************************************************************/
static void VS_log_Screen(LOG_LEVELS level,\
LOG_MODULES module,\
char* format,\
va_list ap)\
static void VS_log_Screen(LOG_LEVELS level,
LOG_MODULES module,
char* format,
va_list ap)
{
char MsgBuff[LOGBUFF_MAXSIZE+20];
char MsgBuff[LOGBUFF_MAXSIZE]; /* buffer which will contain
the message wanted to be displayed */
char LineBuff[LOGBUFF_LINESIZE]; /* line currently displayed */
char HeaderBuff[34+20]; /* header of the message + color */
char FooterBuff[20]; /* footer of the message + end color */
int MessagePosition;
int MessageLength;
time_t MsgTime;
struct tm * ptmTime;
......@@ -155,7 +189,7 @@ static void VS_log_Screen(LOG_LEVELS level,\
/* Record the time */
time(&MsgTime);
ptmTime=localtime(&MsgTime);
sprintf(MsgBuff, "%02i/%02i %02i:%02i:%02i ", ptmTime->tm_mday,
sprintf(HeaderBuff, "%02i/%02i %02i:%02i:%02i ", ptmTime->tm_mday,
ptmTime->tm_mon+1, ptmTime->tm_hour,
ptmTime->tm_min, ptmTime->tm_sec);
......@@ -165,30 +199,30 @@ static void VS_log_Screen(LOG_LEVELS level,\
switch (module)
{
case SNMP:
sprintf(MsgBuff+strlen(MsgBuff), "[SNMP : ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[SNMP : ");
break;
case SERVER:
sprintf(MsgBuff+strlen(MsgBuff), "[SERVER: ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[SERVER: ");
break;
case DB:
sprintf(MsgBuff+strlen(MsgBuff), "[DB : ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[DB : ");
break;
case CFG:
sprintf(MsgBuff+strlen(MsgBuff), "[CFG : ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[CFG : ");
break;
case IF:
sprintf(MsgBuff+strlen(MsgBuff), "[IF : ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[IF : ");
break;
case TELNET:
sprintf(MsgBuff+strlen(MsgBuff), "[TELNET: ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[TELNET: ");
break;
case LOGGER:
sprintf(MsgBuff+strlen(MsgBuff), "[LOGGER: ");
sprintf(HeaderBuff+strlen(HeaderBuff), "[LOGGER: ");
break;
}
......@@ -196,49 +230,59 @@ static void VS_log_Screen(LOG_LEVELS level,\
switch (level)
{
case LOGDEBUG:
sprintf(MsgBuff+strlen(MsgBuff), "debug ] ");
sprintf(HeaderBuff+strlen(HeaderBuff), "debug ] ");
break;
case LOGINFO:
sprintf(MsgBuff+strlen(MsgBuff), "info ] ");
sprintf(HeaderBuff+strlen(HeaderBuff), "info ] ");
break;
case LOGWARNING:
sprintf(MsgBuff+strlen(MsgBuff), "Warning ] ");
sprintf(HeaderBuff+strlen(HeaderBuff), "Warning ] ");
break;
case LOGFATAL:
{
#ifdef LINUX_COLOR
int i=strlen(MsgBuff);
MsgBuff[i]=27;
MsgBuff[i+1]='\0';
sprintf(MsgBuff+strlen(MsgBuff), "[40;31;1m");
sprintf(HeaderBuff+strlen(HeaderBuff), "\033[40;31;1m");
#endif
sprintf(MsgBuff+strlen(MsgBuff), "FATAL ] ");
sprintf(HeaderBuff+strlen(HeaderBuff), "FATAL ] ");
break;
}
case LOGERROR:
{
#ifdef LINUX_COLOR
int i=strlen(MsgBuff);
MsgBuff[i]=27;
MsgBuff[i+1]='\0';
sprintf(MsgBuff+strlen(MsgBuff), "[40;31;1m");
sprintf(HeaderBuff+strlen(HeaderBuff), "\033[40;31;1m");
#endif
sprintf(MsgBuff+strlen(MsgBuff), "ERROR ] ");
sprintf(HeaderBuff+strlen(HeaderBuff), "ERROR ] ");
break;
}
}
/* XXX No error checking ! What length is the message ? */
vsnprintf(MsgBuff+strlen(MsgBuff), LOGBUFF_MAXSIZE, format, ap);
{
int i=strlen(MsgBuff);
MsgBuff[i]=27;
MsgBuff[i+1]=0;
sprintf(MsgBuff+strlen(MsgBuff), "[0m\n");
}
vsnprintf(MsgBuff, LOGBUFF_MAXSIZE, format, ap);
#ifdef LINUX_COLOR
sprintf(FooterBuff, "\033[0m\n");
#else
sprintf(FooterBuff,"\n");
#endif
pthread_mutex_lock(&ptmLogScreen);
fprintf(stderr, "%s", MsgBuff);
/* Now the message is completely build, it can be displayed */
fputs( HeaderBuff, stderr );
MessageLength = strlen(MsgBuff);
MessagePosition = 0;
while ( (MessageLength-MessagePosition) > LOGBUFF_LINESIZE )
{
snprintf( LineBuff, LOGBUFF_LINESIZE+1, MsgBuff + MessagePosition );
fputs( LineBuff, stderr );
fputs( "\n ", stderr );
MessagePosition += LOGBUFF_LINESIZE;
}
fputs( MsgBuff + MessagePosition, stderr);
fputs(FooterBuff, stderr);
pthread_mutex_unlock(&ptmLogScreen);
#ifndef DEBUG
}
......@@ -254,23 +298,19 @@ static void VS_log_Screen(LOG_LEVELS level,\
void VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...)
{
va_list ap;
va_start(ap,format);
if (method==LOG_FILE_ONLY)
if (method & LOG_FILE)
{
VS_log_File(level, module,format,ap);
}
else if (method==LOG_SCREEN_ONLY)
{
VS_log_Screen(level, module,format,ap);
}
else if (method==LOG_BOTH)
if (method & LOG_SCREEN)
{
VS_log_File(level, module,format,ap);
VS_log_Screen(level, module,format,ap);
}
va_end(ap);
va_end(ap);
}
......@@ -335,27 +375,21 @@ int CloseLogFile ()
*****************************************************************************/
int LOG_init(char * sLogName, unsigned char ucM)
{
switch (ucM)
method=0;
if (ucM!=LOG_NONE)
{
case LOG_SCREEN_ONLY:
pthread_mutex_init(&ptmLogScreen, NULL);
method=LOG_SCREEN_ONLY;
VS_log(LOGINFO,LOGGER,"Logs inited on screen");
break;
case LOG_FILE_ONLY:
OpenLogFile(sLogName);
method=LOG_FILE_ONLY;
VS_log(LOGINFO,LOGGER,"Logs inited with file: %s",sLogName);
break;
case LOG_BOTH:
if (ucM & LOG_SCREEN)
{
method |= LOG_SCREEN;
pthread_mutex_init(&ptmLogScreen, NULL);
VS_log(LOGINFO, LOGGER, "Logs inited on screen");
}
if (ucM & LOG_FILE)
{
method |= LOG_FILE;
OpenLogFile(sLogName);
method=LOG_BOTH;
VS_log(LOGINFO,LOGGER,"Logs inited on screen and with file: %s",\
sLogName);
break;
VS_log(LOGINFO, LOGGER, "Logs inited with file : %s", sLogName);
}
}
return 0;
}
......@@ -369,96 +403,42 @@ int LOG_init(char * sLogName, unsigned char ucM)
*****************************************************************************/
int LOG_change(char * sLogName, unsigned char ucM)
{
switch (ucM)
{
case LOG_NONE:
switch (method)
{
case LOG_FILE_ONLY:
CloseLogFile();
break;
case LOG_SCREEN_ONLY:
pthread_mutex_destroy(&ptmLogScreen);
break;
case LOG_BOTH:
CloseLogFile();
pthread_mutex_destroy(&ptmLogScreen);
break;
}
method=LOG_NONE;
break;
case LOG_SCREEN_ONLY:
switch (method)
{
case LOG_BOTH:
CloseLogFile();
break;
case LOG_FILE_ONLY:
CloseLogFile();
case LOG_NONE:
pthread_mutex_init(&ptmLogScreen, NULL);
break;
}
method=LOG_SCREEN_ONLY;
VS_log(LOGINFO,LOGGER,"Logs inited on screen");
break;
case LOG_FILE_ONLY:
switch (method)
{
case LOG_BOTH:
pthread_mutex_destroy(&ptmLogScreen);
CloseLogFile();
OpenLogFile(sLogName);
break;
case LOG_SCREEN_ONLY:
pthread_mutex_destroy(&ptmLogScreen);
case LOG_NONE:
OpenLogFile(sLogName);
break;
case LOG_FILE_ONLY:
CloseLogFile();
OpenLogFile(sLogName);
break;
}
VS_log(LOGINFO,LOGGER,"Logs inited with file: %s",sLogName);
method=LOG_FILE_ONLY;
break;
int old_method = method;
method = 0; /* reinit the log method */
/*
* Deals with the logs on file
*/
if (old_method & LOG_FILE)
{ /* if a log file was opened : close it */
CloseLogFile();
}
if (ucM & LOG_FILE)
{ /* open a log file if requested */
OpenLogFile(sLogName);
method |= LOG_FILE;
VS_log(LOGINFO,LOGGER,"Logs inited with file: %s",sLogName);
}
case LOG_BOTH:
switch (method)
{
case LOG_FILE_ONLY:
CloseLogFile();
case LOG_NONE:
OpenLogFile(sLogName);
pthread_mutex_init(&ptmLogScreen, NULL);
break;
case LOG_SCREEN_ONLY:
OpenLogFile(sLogName);
break;
case LOG_BOTH:
CloseLogFile();
OpenLogFile(sLogName);
break;
}
method=LOG_BOTH;
VS_log(LOGINFO,LOGGER,"Logs inited on screen and with file: %s",\
sLogName);
break;
/*
* Deals with the logs on screen
*/
if (ucM & LOG_SCREEN)
{
if ( !(old_method & LOG_SCREEN) )
{ /* if the log on screen wasn't already inited */
pthread_mutex_init(&ptmLogScreen, NULL);
}
method |= LOG_SCREEN;
VS_log(LOGINFO,LOGGER,"Logs inited on screen");
}
else
{
if ( old_method & LOG_SCREEN )
{ /* if it is requested to stop screen logging, stop it ! */
pthread_mutex_destroy(&ptmLogScreen);
}
}
return 0;
}
......@@ -467,13 +447,14 @@ int LOG_change(char * sLogName, unsigned char ucM)
/****************************************************************************
* LOG_close() : Close the log process
****************************************************************************
* TODO Write it !
* TODO Write a maybe more complete function.
****************************************************************************/
int LOG_close()
{
/* switch back to the no-logs option*/
return LOG_change(NULL, LOG_NONE);
}
/****************************************************************************
* VS_log_errstr() : Returns a string corresponding to an ERR_CODE
......
......@@ -3,7 +3,7 @@
* Header file for logger.c
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: logger.h,v 1.10 2001/04/29 03:41:49 nitrox Exp $
* $Id: logger.h,v 1.11 2001/05/15 22:57:23 marcari Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
*
......@@ -27,11 +27,11 @@
/* Methods for logger */
#define LOG_NONE 0
#define LOG_FILE_ONLY 1
#define LOG_SCREEN_ONLY 2
#define LOG_BOTH 3
#define LOG_FILE 1
#define LOG_SCREEN 2
#define LOGBUFF_MAXSIZE 120
#define LOGBUFF_MAXSIZE 460
#define LOGBUFF_LINESIZE 46
char * VS_log_errstr(ERR_CODE err);
......@@ -39,4 +39,5 @@ void VS_log(LOG_LEVELS level, LOG_MODULES module, char * format, ...);
int LOG_init(char * sLogName, unsigned char ucM);
int LOG_change(char * sLogName, unsigned char ucM);
int LOG_close();
#endif
......@@ -3,7 +3,7 @@
* Init of the VLANserver
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: types.c,v 1.21 2001/04/29 03:41:49 nitrox Exp $
* $Id: types.c,v 1.22 2001/05/15 22:57:23 marcari Exp $
*
* Authors: Brieuc Jeunhomme <bbp@via.ecp.fr>
*
......@@ -84,7 +84,7 @@ unsigned int VS_init(int argc,char *argv[])
// Starting the server
grumpf=VS_start();
if (grumpf);
if (grumpf)
return grumpf;
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment