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);
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;
}
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;
}
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;
}
#include "objson/object.h"
#include "objson/json_parser.h"
#include "memcache.h"
+#include "log.h"
/**
osrfCache is a globally shared cache API
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 */
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 );
}
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) {
}
fprintf(file, "%s %s %s\n", __osrfLogAppname, datebuf, VA_BUF );
- fclose(file);
+ if( fclose(file) != 0 )
+ osrfLogWarning("Error closing log file: %s", strerror(errno));
+
}
#include <stdio.h>
#include "utils.h"
#include <time.h>
+#include <errno.h>
#ifndef OSRF_LOG_INCLUDED
#define OSRF_LOG_INCLUDED
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" );
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;
// 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;
}
}
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;
}