From: erickson Date: Wed, 30 Nov 2005 18:38:16 +0000 (+0000) Subject: removed these since the C code is now using the unified log code in utils/log.* X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4079a8e6bb56cb48c971507691479d7cb62ad70b;p=working%2FOpenSRF.git removed these since the C code is now using the unified log code in utils/log.* git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@589 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/libstack/osrf_log.c b/src/libstack/osrf_log.c deleted file mode 100644 index b144814..0000000 --- a/src/libstack/osrf_log.c +++ /dev/null @@ -1,67 +0,0 @@ -#include "osrf_log.h" -#include - -char* __osrfLogAppName = NULL; -char* __osrfLogDir = NULL; -int __osrfLogLevel = 1; - -int osrfLogInit(char* appname) { - - if( !appname ) return -1; - osrfLogInfo("Initing application log for app %s", appname ); - - char* dir = osrf_settings_host_value("/dirs/log"); - if(!dir) return osrfLogWarning("No '/dirs/log' setting in host config"); - - char* level = osrfConfigGetValue(NULL, "/loglevel"); - if(level) { __osrfLogLevel = atoi(level); free(level); } - - __osrfLogAppName = strdup(appname); - __osrfLogDir = strdup(dir); - return 0; -} - - -void osrfLog( enum OSRF_LOG_LEVEL level, char* msg, ... ) { - - if( !(__osrfLogDir && __osrfLogAppName) ) return; - if( level > __osrfLogLevel ) return; - - time_t t = time(NULL); - struct tm* tms = localtime(&t); - - char datebuf[24]; - bzero(datebuf, 24); - strftime( datebuf, 23, "%d%m%Y", tms ); - - char timebuf[24]; - bzero(timebuf, 24); - strftime( timebuf, 23, "%Y:%m:%d %H:%M:%S", tms ); - - char millis[12]; - bzero(millis, 12); - double d = get_timestamp_millis(); - d = d - (int) d; - sprintf(millis, "%.6f", d); - - - char* filename = va_list_to_string( - "%s/%s.%s.log", __osrfLogDir, __osrfLogAppName, datebuf); - - FILE* file = fopen(filename, "a"); - free(filename); - - if(!file) { - osrfLogWarning("Unable to open application log file %s\n", filename); - return; - } - - VA_LIST_TO_STRING(msg); - fprintf(file, "[%s.%s %d %d] %s\n", timebuf, millis + 2, getpid(), level, VA_BUF ); - fclose(file); - - if( level == OSRF_ERROR ) - fprintf(stderr, "[%s.%s %d %d] %s\n", timebuf, millis + 2, getpid(), level, VA_BUF ); -} - - diff --git a/src/libstack/osrf_log.h b/src/libstack/osrf_log.h deleted file mode 100644 index 5daf2e4..0000000 --- a/src/libstack/osrf_log.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "opensrf/utils.h" -#include "osrf_settings.h" -#include "osrfConfig.h" - -enum OSRF_LOG_LEVEL { OSRF_ERROR = 1, OSRF_WARN = 2, OSRF_INFO = 3, OSRF_DEBUG = 4 }; - -int osrfLogInit(char* appname); -void osrfLog( enum OSRF_LOG_LEVEL, char* msg, ... ); - diff --git a/src/utils/logging.c b/src/utils/logging.c deleted file mode 100644 index 1a993d3..0000000 --- a/src/utils/logging.c +++ /dev/null @@ -1,232 +0,0 @@ -#include -#include "logging.h" - -void get_timestamp( char buf_36chars[]) { - - struct timeb tb; - ftime(&tb); - char* localtime = strdup( ctime( &(tb.time) ) ); - char mil[4]; - memset(mil,0,4); - sprintf(mil," (%d)",tb.millitm); - strcpy( buf_36chars, localtime ); - buf_36chars[ strlen(localtime)-1] = '\0'; // remove newline - strcat(buf_36chars,mil); - free(localtime); -} - -static char* lf = NULL; -static int log_level = -1; -static int logging = 0; - -void log_free() { if( lf != NULL ) free(lf); } - -int fatal_handler( char* msg, ... ) { - - FILE * log_file; - - char buf[36]; - memset( buf, 0, 36 ); - get_timestamp( buf ); - pid_t pid = getpid(); - va_list args; - - if( logging ) { - if( log_level < OSRF_LOG_ERROR ) - return -1; - - log_file = fopen( lf, "a" ); - if( log_file == NULL ) { - perror( "Unable to open log file for appending\n" ); - } else { - - fprintf( log_file, "[%s %d] [%s] ", buf, pid, "ERR " ); - - va_start(args, msg); - vfprintf(log_file, msg, args); - va_end(args); - - fprintf(log_file, "\n"); - fflush( log_file ); - - fclose(log_file); - } - } - - /* also log to stderr for ERRORS*/ - fprintf( stderr, "[%s %d] [%s] ", buf, pid, "ERR " ); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); - fprintf( stderr, "\n" ); - - exit(99); - return -1; /* for consistency */ -} - -int warning_handler( char* msg, ... ) { - - FILE * log_file; - - char buf[36]; - memset( buf, 0, 36 ); - get_timestamp( buf ); - pid_t pid = getpid(); - va_list args; - - if( log_level < OSRF_LOG_WARNING ) - return -1; - - if(logging) { - - log_file = fopen( lf, "a" ); - if( log_file == NULL ) { - perror( "Unable to open log file for appending\n" ); - fprintf( stderr, "[%s %d] [%s] ", buf, pid, "WARN" ); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); - fprintf( stderr, "\n" ); - } else { - - fprintf( log_file, "[%s %d] [%s] ", buf, pid, "WARN" ); - - va_start(args, msg); - vfprintf(log_file, msg, args); - va_end(args); - - fprintf(log_file, "\n"); - fflush( log_file ); - - fclose(log_file); - } - } else { - - fprintf( stderr, "[%s %d] [%s] ", buf, pid, "WARN" ); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); - fprintf( stderr, "\n" ); - } - - return -1; -} - -int info_handler( char* msg, ... ) { - - FILE * log_file; - - char buf[36]; - memset( buf, 0, 36 ); - get_timestamp( buf ); - pid_t pid = getpid(); - va_list args; - - if( log_level < OSRF_LOG_INFO ) - return -1; - - if(logging) { - - log_file = fopen( lf, "a" ); - if( log_file == NULL ) { - perror( "Unable to open log file for appending\n" ); - fprintf( stderr, "[%s %d] [%s] ", buf, pid, "INFO" ); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); - fprintf( stderr, "\n" ); - fflush(stderr); - } else { - - fprintf( log_file, "[%s %d] [%s] ", buf, pid, "INFO" ); - - va_start(args, msg); - vfprintf(log_file, msg, args); - va_end(args); - - fprintf(log_file, "\n"); - fflush( log_file ); - fclose(log_file); - } - } else { - - fprintf( stderr, "[%s %d] [%s] ", buf, pid, "INFO" ); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); - fprintf( stderr, "\n" ); - fflush(stderr); - - } - return -1; -} - - -int debug_handler( char* msg, ... ) { - - FILE * log_file; - - char buf[36]; - memset( buf, 0, 36 ); - get_timestamp( buf ); - pid_t pid = getpid(); - va_list args; - - if( log_level < OSRF_LOG_DEBUG ) - return -1; - - if(logging) { - - log_file = fopen( lf, "a" ); - if( log_file == NULL ) { - perror( "Unable to open log file for appending\n" ); - fprintf( stderr, "[%s %d] [%s] ", buf, pid, "DEBG" ); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); - fprintf( stderr, "\n" ); - } else { - fprintf( log_file, "[%s %d] [%s] ", buf, pid, "DEBG" ); - - va_start(args, msg); - vfprintf(log_file, msg, args); - va_end(args); - - fprintf(log_file, "\n"); - fflush( log_file ); - - fclose(log_file); - } - } else { - - fprintf( stderr, "[%s %d] [%s] ", buf, pid, "DEBG" ); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); - fprintf( stderr, "\n" ); - } - - return -1; -} - - -int log_init( int llevel, char* lfile ) { - - - if( llevel < 1 ) { - logging = 0; - return 0; - } - - /* log to stderr */ - if(lfile == NULL) return 0; - - log_level = llevel; - lf = strdup(lfile); - - logging = 1; - return 1; - -} - - diff --git a/src/utils/logging.h b/src/utils/logging.h deleted file mode 100644 index 5e8f7bc..0000000 --- a/src/utils/logging.h +++ /dev/null @@ -1,42 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#ifndef LOGGING_H -#define LOGGING_H - - -#define OSRF_LOG_ERROR 1 -#define OSRF_LOG_WARNING 2 -#define OSRF_LOG_INFO 3 -#define OSRF_LOG_DEBUG 4 -#define OSRF_LOG_INTERNAL 5 -#define OSRF_LOG_ACTIVITY 6 - -// --------------------------------------------------------------------------------- -// Error handling interface. -// --------------------------------------------------------------------------------- -void get_timestamp( char buf_36chars[]); -int fatal_handler( char* message, ...); -int warning_handler( char* message, ... ); -int info_handler( char* message, ... ); -int debug_handler( char* message, ... ); - - -/** If we return 0 either the log level is less than LOG_ERROR - * or we could not open the log file - */ -int log_init( int log_level, char* log_file ); -void log_free(); - -#endif