From c8b4d5edf73198db1b942e0a19ed7072b61c1e94 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 1 Dec 2005 18:48:51 +0000 Subject: [PATCH] added some log statements, fixed some typos git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@592 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libstack/osrf_cache.c | 7 ++++++- src/libstack/osrf_cache.h | 1 + src/utils/log.c | 17 ++++++++++------- src/utils/log.h | 1 + src/utils/socket_bundle.c | 9 +++------ src/utils/utils.c | 5 ++++- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/libstack/osrf_cache.c b/src/libstack/osrf_cache.c index df5199a..9c06508 100644 --- a/src/libstack/osrf_cache.c +++ b/src/libstack/osrf_cache.c @@ -34,6 +34,7 @@ int osrfCacheInit( char* serverStrings[], int size, time_t maxCacheSeconds ) { int osrfCachePutObject( char* key, const jsonObject* obj, time_t seconds ) { if( !(key && obj) ) return -1; char* s = jsonObjectToJSON( obj ); + osrfLogInternal("osrfCachePut(): Putting object: %s", s); if( seconds < 0 ) seconds = __osrfCacheMaxSeconds; mc_set(__osrfCache, key, strlen(key), s, strlen(s), seconds, 0); @@ -44,6 +45,7 @@ int osrfCachePutObject( char* key, const jsonObject* obj, time_t seconds ) { int osrfCachePutString( char* key, const char* value, time_t seconds ) { if( !(key && value) ) return -1; if( seconds < 0 ) seconds = __osrfCacheMaxSeconds; + osrfLogInternal("osrfCachePutString(): Putting string: %s", value); mc_set(__osrfCache, key, strlen(key), value, strlen(value), seconds, 0); return 0; } @@ -54,6 +56,7 @@ jsonObject* osrfCacheGetObject( char* key, ... ) { VA_LIST_TO_STRING(key); char* data = (char*) mc_aget( __osrfCache, VA_BUF, strlen(VA_BUF) ); if( data ) { + osrfLogInternal("osrfCacheGetObject(): Returning object: %s", data); obj = jsonParseString( data ); return obj; } @@ -64,7 +67,9 @@ jsonObject* osrfCacheGetObject( char* key, ... ) { char* osrfCacheGetString( char* key, ... ) { if( key ) { VA_LIST_TO_STRING(key); - return (char*) mc_aget(__osrfCache, VA_BUF, strlen(VA_BUF) ); + char* data = (char*) mc_aget(__osrfCache, VA_BUF, strlen(VA_BUF) ); + osrfLogInternal("osrfCacheGetObject(): Returning object: %s", data); + return data; } return NULL; } diff --git a/src/libstack/osrf_cache.h b/src/libstack/osrf_cache.h index 664036a..2159bdd 100644 --- a/src/libstack/osrf_cache.h +++ b/src/libstack/osrf_cache.h @@ -17,6 +17,7 @@ GNU General Public License for more details. #include "objson/object.h" #include "objson/json_parser.h" #include "memcache.h" +#include "log.h" /** osrfCache is a globally shared cache API diff --git a/src/utils/log.c b/src/utils/log.c index eb6a100..40ec051 100644 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -63,7 +63,7 @@ void osrfLogError( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_ERROR); } void osrfLogWarning( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_WARNING); } void osrfLogInfo( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_INFO); } void osrfLogDebug( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_DEBUG); } -void osrfLogInternal( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_DEBUG); } +void osrfLogInternal( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_INTERNAL); } void osrfLogActivity( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_ACTIVITY); /* activity log entries are also logged as info intries */ @@ -125,7 +125,7 @@ void osrfLogDetail( int level, char* filename, int line, char* func, char* msg, syslog( fac | lvl, "[%s:%d:%s:%s:%s] %s", l, getpid(), filename, lb, func, VA_BUF ); else if( __osrfLogType == OSRF_LOG_TYPE_FILE ) - _osrfLogToFile("[%s:%d:%s:%d:%s] %s", l, getpid(), filename, lb, func, VA_BUF ); + _osrfLogToFile("[%s:%d:%s:%s:%s] %s", l, getpid(), filename, lb, func, VA_BUF ); } @@ -136,15 +136,16 @@ void _osrfLogToFile( char* msg, ... ) { VA_LIST_TO_STRING(msg); if(!__osrfLogAppname) __osrfLogAppname = strdup("osrf"); - int l = strlen(VA_BUF) + strlen(__osrfLogAppname) + 24; + int l = strlen(VA_BUF) + strlen(__osrfLogAppname) + 36; char buf[l]; bzero(buf,l); - char datebuf[24]; - bzero(datebuf,24); + + char datebuf[36]; + bzero(datebuf,36); time_t t = time(NULL); struct tm* tms = localtime(&t); - strftime(datebuf, 24, "%Y-%m-%d %h:%m:%s", tms); + strftime(datebuf, 36, "%Y-%m-%d %h:%m:%s", tms); FILE* file = fopen(__osrfLogFile, "a"); if(!file) { @@ -153,7 +154,9 @@ void _osrfLogToFile( char* msg, ... ) { } fprintf(file, "%s %s %s\n", __osrfLogAppname, datebuf, VA_BUF ); - fclose(file); + if( fclose(file) != 0 ) + osrfLogWarning("Error closing log file: %s", strerror(errno)); + } diff --git a/src/utils/log.h b/src/utils/log.h index a425f97..3933ca6 100644 --- a/src/utils/log.h +++ b/src/utils/log.h @@ -2,6 +2,7 @@ #include #include "utils.h" #include +#include #ifndef OSRF_LOG_INCLUDED #define OSRF_LOG_INCLUDED diff --git a/src/utils/socket_bundle.c b/src/utils/socket_bundle.c index f1ae720..70d94ba 100644 --- a/src/utils/socket_bundle.c +++ b/src/utils/socket_bundle.c @@ -404,9 +404,6 @@ void socket_disconnect(socket_manager* mgr, int sock_fd) { osrfLogDebug("Closing socket %d", sock_fd); - if( shutdown( sock_fd, SHUT_RDWR ) ) - osrfLogWarning( "socket_disconnect(): Error shuting down socket, removing anyway" ); - if( close( sock_fd ) == -1 ) osrfLogWarning( "socket_disconnect(): Error closing socket, removing anyway" ); @@ -477,7 +474,7 @@ int socket_wait_all(socket_manager* mgr, int timeout) { socket_node* node = mgr->socket; int max_fd = 0; while(node) { - //osrfLogDebug("Adding socket %d to select set",node->sock_fd); + osrfLogInternal("Adding socket fd %d to select set",node->sock_fd); FD_SET( node->sock_fd, &read_set ); if(node->sock_fd > max_fd) max_fd = node->sock_fd; node = node->next; @@ -492,16 +489,16 @@ int socket_wait_all(socket_manager* mgr, int timeout) { // If timeout is -1, there is no timeout passed to the call to select if( (retval = select( max_fd, &read_set, NULL, NULL, NULL)) == -1 ) { + osrfLogWarning("Call to select interrupted (returned -1)"); osrfLogWarning("Sys Error: %s", strerror(errno)); - osrfLogWarning("Call to select interrupted"); return -1; } } else if( timeout != 0 ) { /* timeout of 0 means don't block */ if( (retval = select( max_fd, &read_set, NULL, NULL, &tv)) == -1 ) { + osrfLogWarning( "Call to select interrupted (returned -1)" ); osrfLogWarning("Sys Error: %s", strerror(errno)); - osrfLogWarning( "Call to select interrupted" ); return -1; } } diff --git a/src/utils/utils.c b/src/utils/utils.c index cc1e284..bfeafb9 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -381,7 +381,10 @@ char* file_to_string(const char* filename) { FILE* file = fopen(filename, "r"); if(!file) { - perror("Unable to open file in json_parse_file()"); + int l = strlen(filename) + 64; + char b[l]; + snprintf(b,l,"Unable to open file [%s] in file_to_string()", filename); + perror(b); return NULL; } -- 2.11.0