got log.c compiling and formating changes and comments

ulab-original
jsorg71 19 years ago
parent 466e36d615
commit 7964620914

@ -29,11 +29,14 @@
#include "log.h"
/* this gets created in log_start and freed in log_end */
static struct log_config* l_cfg;
/* threading additions */
#ifdef LOG_ENABLE_THREAD
#include "nptl/pthread.h"
#include "pthread.h"
/* these get initalized in log_start, they don't need
to get freed */
static pthread_mutex_t log_lock;
static pthread_mutexattr_t log_lock_attr;
#endif
@ -45,9 +48,11 @@ static pthread_mutexattr_t log_lock_attr;
* @return see open(2) return values
*
*/
static int log_file_open(const char* fname)
static int DEFAULT_CC
log_file_open(const char* fname)
{
return open(fname, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, S_IRUSR | S_IWUSR);
return open(fname, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, S_IRUSR |
S_IWUSR);
}
/**
@ -57,7 +62,8 @@ static int log_file_open(const char* fname)
* @return syslog equivalent logging level
*
*/
static int log_xrdp2syslog(const int lvl)
static int DEFAULT_CC
log_xrdp2syslog(const int lvl)
{
switch (lvl)
{
@ -83,23 +89,30 @@ static int log_xrdp2syslog(const int lvl)
* @return syslog equivalent logging level
*
*/
void log_lvl2str(int lvl, char* str)
void DEFAULT_CC
log_lvl2str(int lvl, char* str)
{
switch (lvl)
{
case LOG_LEVEL_ALWAYS:
snprintf(str, 9, "%s", "[CORE ] ");
break;
case LOG_LEVEL_ERROR:
snprintf(str, 9, "%s", "[ERROR] ");
break;
case LOG_LEVEL_WARNING:
snprintf(str, 9, "%s", "[WARN ] ");
break;
case LOG_LEVEL_INFO:
snprintf(str, 9, "%s", "[INFO ] ");
break;
/* case LOG_LEVEL_DEBUG: */
default:
snprintf(str, 9, "%s", "[DEBUG] ");
break;
}
}
/******************************************************************************/
int DEFAULT_CC
log_message(const unsigned int lvl, const char* msg, ...)
@ -123,8 +136,9 @@ log_message(const unsigned int lvl, const char* msg, ...)
now_t = time(&now_t);
now = localtime(&now_t);
snprintf(buff, 21, "[%.4d%.2d%.2d-%.2d:%.2d:%.2d] ", (now->tm_year)+1900, (now->tm_mon)+1,
now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec);
snprintf(buff, 21, "[%.4d%.2d%.2d-%.2d:%.2d:%.2d] ", (now->tm_year) + 1900,
(now->tm_mon) + 1, now->tm_mday, now->tm_hour, now->tm_min,
now->tm_sec);
log_lvl2str(lvl, buff + 20);
@ -226,7 +240,10 @@ log_start(const char* progname, const char* logfile, const unsigned int loglvl,
}
/* if syslog is enabled, open it */
if (l_cfg->enable_syslog) openlog(l_cfg->program_name, LOG_CONS | LOG_PID, LOG_DAEMON);
if (l_cfg->enable_syslog)
{
openlog(l_cfg->program_name, LOG_CONS | LOG_PID, LOG_DAEMON);
}
#ifdef LOG_ENABLE_THREAD
pthread_mutexattr_init(&log_lock_attr);
@ -252,14 +269,20 @@ log_end()
if (0 > l_cfg->fd)
{
/* if syslog is enabled, close it */
if (l_cfg->enable_syslog) closelog();
if (l_cfg->enable_syslog)
{
closelog();
}
}
/* closing logfile... */
g_file_close(l_cfg->fd);
/* if syslog is enabled, close it */
if (l_cfg->enable_syslog) closelog();
if (l_cfg->enable_syslog)
{
closelog();
}
/* freeing allocated memory */
g_free(l_cfg->log_file);
@ -294,9 +317,9 @@ log_text2level(char* buf)
{
return LOG_LEVEL_INFO;
}
/* else if (0 == g_strncasecmp(buf, "1", 1) ||
0 == g_strncasecmp(buf, "true", 4) ||
0 == g_strncasecmp(buf, "yes", 3))
/* else if (0 == g_strncasecmp(buf, "1", 2) ||
0 == g_strncasecmp(buf, "true", 5) ||
0 == g_strncasecmp(buf, "yes", 4))
{
return LOG_LEVEL_DEBUG;
}*/

Loading…
Cancel
Save