From b3f8a5ed47a22e72307b1f28dc89d5fc8f23e013 Mon Sep 17 00:00:00 2001 From: Ben Thompson Date: Mon, 4 Mar 2019 11:41:25 -0600 Subject: [PATCH] add SMLogging. --- CMakeLists.txt | 3 +- src/AppendTask.cpp | 4 ++- src/CloudStorage.cpp | 5 ++-- src/CopyTask.cpp | 6 ++-- src/IOCoordinator.cpp | 6 ++-- src/ListDirectoryTask.cpp | 4 ++- src/OpenTask.cpp | 4 ++- src/PosixTask.cpp | 9 ++++-- src/ProcessTask.cpp | 5 ++-- src/ReadTask.cpp | 4 ++- src/SMLogging.cpp | 51 +++++++++++++++++++++++++++++++++ src/SMLogging.h | 29 +++++++++++++++++++ src/SessionManager.cpp | 60 ++++++++++++++++++++------------------- src/StatTask.cpp | 4 ++- src/TruncateTask.cpp | 4 ++- src/UnlinkTask.cpp | 4 ++- src/WriteTask.cpp | 4 ++- src/main.cpp | 10 ++----- 18 files changed, 159 insertions(+), 57 deletions(-) mode change 100644 => 100755 CMakeLists.txt create mode 100644 src/SMLogging.cpp create mode 100644 src/SMLogging.h diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index 568045d5d..91a4eeb82 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,10 @@ set(storagemanager_SRCS src/S3Storage.cpp src/LocalStorage.cpp src/Cache.cpp + src/SMLogging.cpp ) -option(TRACE "Enable some tracing output" OFF) +option(TRACE "Enable some tracing output" ON) if (TRACE) add_definitions(-DSM_TRACE) endif() diff --git a/src/AppendTask.cpp b/src/AppendTask.cpp index 5784744d9..5e07557c6 100644 --- a/src/AppendTask.cpp +++ b/src/AppendTask.cpp @@ -1,6 +1,7 @@ #include "AppendTask.h" #include "messageFormat.h" +#include "SMLogging.h" #include using namespace std; @@ -27,6 +28,7 @@ AppendTask::~AppendTask() bool AppendTask::run() { + SMLogging* logger = SMLogging::get(); bool success; uint8_t cmdbuf[1024] = {0}; int err; @@ -44,7 +46,7 @@ bool AppendTask::run() check_error("AppendTask read", false); #ifdef SM_TRACE - syslog(LOG_DEBUG, "append %d bytes to %s.",cmd->count,cmd->filename); + logger->log(LOG_DEBUG,"append %d bytes to %s.",cmd->count,cmd->filename); #endif size_t readCount = 0, writeCount = 0; diff --git a/src/CloudStorage.cpp b/src/CloudStorage.cpp index 9966db0c4..7ad580e01 100644 --- a/src/CloudStorage.cpp +++ b/src/CloudStorage.cpp @@ -3,8 +3,8 @@ #include "Config.h" #include "S3Storage.h" #include "LocalStorage.h" +#include "SMLogging.h" #include -#include #include #include @@ -29,6 +29,7 @@ namespace storagemanager { CloudStorage * CloudStorage::get() { + SMLogging* logger = SMLogging::get(); if (inst) return inst; @@ -42,7 +43,7 @@ CloudStorage * CloudStorage::get() else if (type == "local") inst = new LocalStorage(); else { - syslog(LOG_CRIT, "CloudStorage: got unknown service provider: %s", type.c_str()); + logger->log(LOG_CRIT,"CloudStorage: got unknown service provider: %s", type.c_str()); return NULL; } diff --git a/src/CopyTask.cpp b/src/CopyTask.cpp index 9799cc766..76482d6d1 100644 --- a/src/CopyTask.cpp +++ b/src/CopyTask.cpp @@ -1,7 +1,7 @@ #include "CopyTask.h" #include -#include "syslog.h" +#include "SMLogging.h" #include "messageFormat.h" using namespace std; @@ -27,6 +27,8 @@ CopyTask::~CopyTask() bool CopyTask::run() { bool success; + SMLogging* logger = SMLogging::get(); + uint8_t buf[2048] = {0}; if (getLength() > 2047) @@ -42,7 +44,7 @@ bool CopyTask::run() f_name *filename2 = (f_name *) &buf[sizeof(copy_cmd) + cmd->file1.flen]; #ifdef SM_TRACE - syslog(LOG_DEBUG, "copy %s to %s.",filename1,filename2); + logger->log(LOG_DEBUG,"copy %s to %s.",filename1.c_str(),filename2->filename); #endif int err = ioc->copyFile(filename1.c_str(), filename2->filename); diff --git a/src/IOCoordinator.cpp b/src/IOCoordinator.cpp index fec219de4..d11384d72 100644 --- a/src/IOCoordinator.cpp +++ b/src/IOCoordinator.cpp @@ -1,9 +1,8 @@ #include "IOCoordinator.h" - +#include "SMLogging.h" #include #include -#include #include #include #include @@ -191,6 +190,7 @@ int IOCoordinator::unlink(const char *path) int IOCoordinator::copyFile(const char *filename1, const char *filename2) { + SMLogging* logger = SMLogging::get(); int err = 0, l_errno; try { boost::filesystem::copy_file(filename1, filename2); @@ -200,7 +200,7 @@ int IOCoordinator::copyFile(const char *filename1, const char *filename2) l_errno = e.code().value(); // why not. // eh, not going to translate all of boost's errors into our errors for this. // log the error - syslog(LOG_ERR, "IOCoordinator::copy(): got %s",e.what()); + logger->log(LOG_ERR,"IOCoordinator::copy(): got %s",e.what()); } catch (...) { err = -1; diff --git a/src/ListDirectoryTask.cpp b/src/ListDirectoryTask.cpp index cdc5b22b3..67f87c637 100644 --- a/src/ListDirectoryTask.cpp +++ b/src/ListDirectoryTask.cpp @@ -1,5 +1,6 @@ #include "ListDirectoryTask.h" +#include "SMLogging.h" #include "messageFormat.h" #include #include @@ -57,6 +58,7 @@ bool ListDirectoryTask::writeString(uint8_t *buf, int *offset, int size, const s bool ListDirectoryTask::run() { + SMLogging* logger = SMLogging::get(); bool success; uint8_t buf[1024] = {0}; int err; @@ -71,7 +73,7 @@ bool ListDirectoryTask::run() listdir_cmd *cmd = (listdir_cmd *) buf; #ifdef SM_TRACE - syslog(LOG_DEBUG, "list_directory %s.",cmd->path); + logger->log(LOG_DEBUG,"list_directory %s.",cmd->path); #endif vector listing; diff --git a/src/OpenTask.cpp b/src/OpenTask.cpp index 9ba285a53..00d5e93c9 100644 --- a/src/OpenTask.cpp +++ b/src/OpenTask.cpp @@ -2,6 +2,7 @@ #include "OpenTask.h" #include "messageFormat.h" +#include "SMLogging.h" #include #include #include @@ -26,6 +27,7 @@ bool OpenTask::run() call IOManager to do the work return the result */ + SMLogging* logger = SMLogging::get(); bool success; uint8_t buf[1024] = {0}; @@ -45,7 +47,7 @@ bool OpenTask::run() open_cmd *cmd = (open_cmd *) buf; #ifdef SM_TRACE - syslog(LOG_DEBUG, "open filename %s mode %o.",cmd->filename,cmd->openmode); + logger->log(LOG_DEBUG,"open filename %s mode %o.",cmd->filename,cmd->openmode); #endif sm_response *resp = (sm_response *) buf; int err = ioc->open(cmd->filename, cmd->openmode, (struct stat *) &resp->payload); diff --git a/src/PosixTask.cpp b/src/PosixTask.cpp index 9b4cc9e90..3496dad47 100644 --- a/src/PosixTask.cpp +++ b/src/PosixTask.cpp @@ -1,10 +1,10 @@ #include "PosixTask.h" #include "messageFormat.h" +#include "SMLogging.h" #include #include #include -#include #include #define min(x, y) (x < y ? x : y) @@ -34,6 +34,7 @@ PosixTask::~PosixTask() void PosixTask::handleError(const char *name, int errCode) { + SMLogging* logger = SMLogging::get(); char buf[sizeof(sm_response) + 4]; // send an error response if possible @@ -43,7 +44,7 @@ void PosixTask::handleError(const char *name, int errCode) write(*resp, 4); // TODO: construct and log a message - syslog(LOG_ERR, "%s caught an error: %s.",name,strerror_r(errCode, buf, 80)); + logger->log(LOG_ERR,"%s caught an error: %s.",name,strerror_r(errCode, buf, 80)); } uint PosixTask::getRemainingLength() @@ -178,6 +179,8 @@ bool PosixTask::write(const vector &buf) void PosixTask::consumeMsg() { + SMLogging* logger = SMLogging::get(); + uint8_t buf[1024]; int err; @@ -187,7 +190,7 @@ void PosixTask::consumeMsg() while (remainingLengthInStream > 0) { - syslog(LOG_ERR, "ERROR: eating data."); + logger->log(LOG_ERR,"ERROR: eating data."); err = ::recv(sock, buf, min(remainingLengthInStream, 1024), 0); if (err <= 0) { remainingLengthInStream = 0; diff --git a/src/ProcessTask.cpp b/src/ProcessTask.cpp index 57a6de906..c885a07d8 100644 --- a/src/ProcessTask.cpp +++ b/src/ProcessTask.cpp @@ -4,7 +4,6 @@ #include #include "messageFormat.h" #include -#include #include #include "AppendTask.h" @@ -18,6 +17,7 @@ #include "UnlinkTask.h" #include "WriteTask.h" #include "SessionManager.h" +#include "SMLogging.h" using namespace std; @@ -37,10 +37,11 @@ ProcessTask::~ProcessTask() void ProcessTask::handleError(int saved_errno) { + SMLogging* logger = SMLogging::get(); SessionManager::get()->socketError(sock); returnedSock = true; char buf[80]; - syslog(LOG_ERR, "ProcessTask: got an error during a socket read: %s.",strerror_r(saved_errno, buf, 80)); + logger->log(LOG_ERR,"ProcessTask: got an error during a socket read: %s.",strerror_r(saved_errno, buf, 80)); } void ProcessTask::operator()() diff --git a/src/ReadTask.cpp b/src/ReadTask.cpp index e1d5b9ffb..c99bfa6cf 100644 --- a/src/ReadTask.cpp +++ b/src/ReadTask.cpp @@ -1,6 +1,7 @@ #include "ReadTask.h" #include "messageFormat.h" +#include "SMLogging.h" #include using namespace std; @@ -27,6 +28,7 @@ ReadTask::~ReadTask() bool ReadTask::run() { + SMLogging* logger = SMLogging::get(); uint8_t buf[1024] = {0}; // get the parameters @@ -41,7 +43,7 @@ bool ReadTask::run() read_cmd *cmd = (read_cmd *) buf; #ifdef SM_TRACE - syslog(LOG_DEBUG, "read %s count %i offset %i.",cmd->filename,cmd->count,cmd->offset); + logger->log(LOG_DEBUG,"read %s count %i offset %i.",cmd->filename,cmd->count,cmd->offset); #endif // read from IOC, write to the socket diff --git a/src/SMLogging.cpp b/src/SMLogging.cpp new file mode 100644 index 000000000..850259817 --- /dev/null +++ b/src/SMLogging.cpp @@ -0,0 +1,51 @@ + +#include +#include +#include "SMLogging.h" + +using namespace std; + +namespace +{ +storagemanager::SMLogging *smLog = NULL; +boost::mutex m; +}; + +namespace storagemanager +{ + +SMLogging::SMLogging() +{ + //TODO: make this configurable + setlogmask (LOG_UPTO (LOG_DEBUG)); + openlog ("StorageManager", LOG_PID | LOG_NDELAY, LOG_LOCAL2); +} + +SMLogging::~SMLogging() +{ + syslog(LOG_INFO, "CloseLog"); + closelog(); +} + +SMLogging * SMLogging::get() +{ + if (smLog) + return smLog; + boost::mutex::scoped_lock s(m); + if (smLog) + return smLog; + smLog = new SMLogging(); + return smLog; +} + +void SMLogging::log(int priority,const char *format, ...) +{ + va_list args; + va_start(args, format); + + vsyslog(priority, format, args); + + va_end(args); +} + +} diff --git a/src/SMLogging.h b/src/SMLogging.h new file mode 100644 index 000000000..9cc376a50 --- /dev/null +++ b/src/SMLogging.h @@ -0,0 +1,29 @@ + +#ifndef SM_LOGGING_H_ +#define SM_LOGGING_H_ + +#include +#include + +namespace storagemanager +{ + +class SMLogging +{ + public: + + static SMLogging *get(); + ~SMLogging(); + + void log(int priority, const char *format, ...); + + private: + SMLogging(); + //SMConfig& config; + +}; + + +} + +#endif diff --git a/src/SessionManager.cpp b/src/SessionManager.cpp index 4ee23f88f..e838264d0 100644 --- a/src/SessionManager.cpp +++ b/src/SessionManager.cpp @@ -12,7 +12,6 @@ #include #include #include -#include using namespace std; #include @@ -20,6 +19,7 @@ using namespace std; #include "messageFormat.h" #include "SessionManager.h" #include "ClientRequestProcessor.h" +#include "SMLogging.h" #include namespace @@ -53,6 +53,7 @@ SessionManager * SessionManager::get() int SessionManager::start() { + SMLogging* logger = SMLogging::get(); int rc,listenSockfd,incomingSockfd,on = 1; struct sockaddr_un addr; int nfds; @@ -61,25 +62,25 @@ int SessionManager::start() int current_size = 0; bool running = true; - syslog(LOG_INFO, "SessionManager starting..."); + logger->log(LOG_INFO,"SessionManager starting..."); if (pipe(socketCtrl)==-1) { - syslog(LOG_CRIT, "Pipe Failed: %s", strerror(errno)); + logger->log(LOG_CRIT,"Pipe Failed: %s", strerror(errno)); return 1; } listenSockfd = ::socket(AF_UNIX, SOCK_STREAM, 0); if (listenSockfd < 0) { - syslog(LOG_CRIT, "socket() failed: %s", strerror(errno)); + logger->log(LOG_CRIT,"socket() failed: %s", strerror(errno)); return -1; } rc = ::setsockopt(listenSockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); if (rc < 0) { - syslog(LOG_CRIT, "setsockopt() failed: %s", strerror(errno)); + logger->log(LOG_CRIT,"setsockopt() failed: %s", strerror(errno)); close(listenSockfd); return -1; } @@ -87,7 +88,7 @@ int SessionManager::start() rc = ::ioctl(listenSockfd, FIONBIO, (char *)&on); if (rc < 0) { - syslog(LOG_CRIT, "ioctl() failed: %s", strerror(errno)); + logger->log(LOG_CRIT,"ioctl() failed: %s", strerror(errno)); close(listenSockfd); return -1; } @@ -98,7 +99,7 @@ int SessionManager::start() rc = ::bind(listenSockfd,(struct sockaddr *)&addr, sizeof(addr)); if (rc < 0) { - syslog(LOG_CRIT, "bind() failed: %s", strerror(errno)); + logger->log(LOG_CRIT,"bind() failed: %s", strerror(errno)); close(listenSockfd); return -1; } @@ -106,7 +107,7 @@ int SessionManager::start() rc = ::listen(listenSockfd, 32); if (rc < 0) { - syslog(LOG_CRIT, "listen() failed: %s", strerror(errno)); + logger->log(LOG_CRIT,"listen() failed: %s", strerror(errno)); close(listenSockfd); return -1; } @@ -118,18 +119,18 @@ int SessionManager::start() fds[1].events = POLLIN; nfds = 2; - syslog(LOG_INFO, "SessionManager waiting for sockets."); + logger->log(LOG_INFO,"SessionManager waiting for sockets."); while (running) { try { //if (current_size != nfds) - //syslog(LOG_DEBUG, "polling %i fds %i", nfds,fds); + //logger->log(LOG_DEBUG,"polling %i fds %i", nfds,fds); //cout << "polling " << nfds << " fds" << endl; rc = ::poll(fds, nfds, pollTimeout); if (rc < 0) { - syslog(LOG_CRIT, "poll() failed: %s", strerror(errno)); + logger->log(LOG_CRIT,"poll() failed: %s", strerror(errno)); break; } current_size = nfds; @@ -139,16 +140,16 @@ int SessionManager::start() if(fds[socketIncr].revents == 0) continue; //if (socketIncr >= 2) - //syslog(LOG_DEBUG, "got event on fd %i index is %i", fds[socketIncr].fd,socketIncr); + //logger->log(LOG_DEBUG,"got event on fd %i index is %i", fds[socketIncr].fd,socketIncr); if(fds[socketIncr].revents != POLLIN) { - //syslog(LOG_DEBUG, "Error! revents = %d", fds[socketIncr].revents,); + //logger->log(LOG_DEBUG,"Error! revents = %d", fds[socketIncr].revents,); close(fds[socketIncr].fd); fds[socketIncr].fd = -1; } if (fds[socketIncr].fd == listenSockfd) { - //syslog(LOG_DEBUG, "Listening socket is readable"); + //logger->log(LOG_DEBUG,"Listening socket is readable"); incomingSockfd = 0; while (incomingSockfd != -1) { @@ -160,12 +161,12 @@ int SessionManager::start() { if (errno != EWOULDBLOCK) { - syslog(LOG_CRIT, "accept() failed: %s", strerror(errno)); + logger->log(LOG_CRIT,"accept() failed: %s", strerror(errno)); running = false; } break; } - //syslog(LOG_DEBUG, "New incoming connection - %d",incomingSockfd); + //logger->log(LOG_DEBUG,"New incoming connection - %d",incomingSockfd); fds[nfds].fd = incomingSockfd; fds[nfds].events = POLLIN; nfds++; @@ -173,7 +174,7 @@ int SessionManager::start() } else if (fds[socketIncr].fd == socketCtrl[0]) { - //syslog(LOG_DEBUG, "SocketControl is readable"); + //logger->log(LOG_DEBUG,"SocketControl is readable"); uint8_t ctrlCode; int len,socket; @@ -194,7 +195,7 @@ int SessionManager::start() { if(fds[i].fd == socket) { - //syslog(LOG_DEBUG, "returned socket %i at index %i", fds[i].fd,i); + //logger->log(LOG_DEBUG,"returned socket %i at index %i", fds[i].fd,i); fds[i].events = POLLIN; break; } @@ -222,7 +223,7 @@ int SessionManager::start() } else { - //syslog(LOG_DEBUG, "socketIncr %d -- Descriptor %d is readable",socketIncr,fds[socketIncr].fd); + //logger->log(LOG_DEBUG,"socketIncr %d -- Descriptor %d is readable",socketIncr,fds[socketIncr].fd); bool closeConn = false; char recv_buffer[8192]; uint recvMsgLength = 0; @@ -233,7 +234,7 @@ int SessionManager::start() struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 100000000; // .1 sec - //syslog(LOG_DEBUG, "reading from fd %i index is %i", fds[socketIncr].fd,socketIncr); + //logger->log(LOG_DEBUG,"reading from fd %i index is %i", fds[socketIncr].fd,socketIncr); if (sockState.find(fds[socketIncr].fd) != sockState.end()) { SockState &state = sockState[fds[socketIncr].fd]; @@ -260,7 +261,7 @@ int SessionManager::start() sockState[fds[socketIncr].fd] = state; break; } - //syslog(LOG_DEBUG, "recv got %i bytes", peakLength); + //logger->log(LOG_DEBUG,"recv got %i bytes", peakLength); endOfData = remainingBytes + peakLength; if (endOfData < SM_HEADER_LEN) { @@ -276,12 +277,12 @@ int SessionManager::start() { if (*((uint *) &recv_buffer[i]) == SM_MSG_START) { - //syslog(LOG_DEBUG, "Received SM_MSG_START"); + //logger->log(LOG_DEBUG,"Received SM_MSG_START"); //found it set msgLength and recvMsgStart offset of SM_MSG_START recvMsgLength = *((uint *) &recv_buffer[i+4]); - //syslog(LOG_DEBUG, "got length = %i", recvMsgLength); + //logger->log(LOG_DEBUG,"got length = %i", recvMsgLength); recvMsgStart = i + SM_HEADER_LEN; - //syslog(LOG_DEBUG, "recvMsgLength %d recvMsgStart %d endofData %d", recvMsgLength,recvMsgStart,endOfData); + //logger->log(LOG_DEBUG,"recvMsgLength %d recvMsgStart %d endofData %d", recvMsgLength,recvMsgStart,endOfData); // if >= endOfData then the start of the message data is the beginning of next message if (recvMsgStart >= endOfData) recvMsgStart = 0; @@ -292,7 +293,7 @@ int SessionManager::start() // didn't find SM_MSG_START in this message consume the data and loop back through on next message if (recvMsgLength == 0) { - //syslog(LOG_DEBUG, "No SM_MSG_START"); + //logger->log(LOG_DEBUG,"No SM_MSG_START"); len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength); assert(len == peakLength); // we know the msg header isn't in position [0, endOfData - i), so throw that out @@ -307,7 +308,7 @@ int SessionManager::start() //remove the junk in front of the message if (recvMsgStart > 0) { - //syslog(LOG_DEBUG, "SM_MSG_START data is here"); + //logger->log(LOG_DEBUG,"SM_MSG_START data is here"); // how many to consume here... // recvMsgStart is the position in the buffer // peakLength is the amount peeked this time @@ -316,7 +317,7 @@ int SessionManager::start() } else { - //syslog(LOG_DEBUG, "SM_MSG_START data is next message"); + //logger->log(LOG_DEBUG,"SM_MSG_START data is next message"); len = ::read(fds[socketIncr].fd, &recv_buffer[remainingBytes], peakLength); } //Disable polling on this socket @@ -327,7 +328,7 @@ int SessionManager::start() /* //Doing this to work with cloudio_component_test len = ::read(fds[socketIncr].fd, out, recvMsgLength); - syslog(LOG_DEBUG, "Read %d bytes.",len); + logger->log(LOG_DEBUG,"Read %d bytes.",len); //Debug test lets send a reponse back uint32_t response[4] = { storagemanager::SM_MSG_START, 8, (uint32_t ) -1, EINVAL }; len = ::send(fds[socketIncr].fd, response, 16, 0); @@ -387,7 +388,8 @@ void SessionManager::returnSocket(int socket) void SessionManager::socketError(int socket) { boost::mutex::scoped_lock s(ctrlMutex); - syslog(LOG_CRIT, " ****** socket error!"); + SMLogging* logger = SMLogging::get(); + logger->log(LOG_CRIT," ****** socket error!"); int err; uint8_t ctrlCode = REMOVEFD; err = ::write(socketCtrl[1], &ctrlCode, 1); diff --git a/src/StatTask.cpp b/src/StatTask.cpp index 04cc6c185..455f5f86f 100644 --- a/src/StatTask.cpp +++ b/src/StatTask.cpp @@ -1,6 +1,7 @@ #include "StatTask.h" #include "messageFormat.h" +#include "SMLogging.h" #include #include #include @@ -29,6 +30,7 @@ StatTask::~StatTask() bool StatTask::run() { + SMLogging* logger = SMLogging::get(); bool success; uint8_t buf[1024] = {0}; @@ -43,7 +45,7 @@ bool StatTask::run() sm_response *resp = (sm_response *) buf; #ifdef SM_TRACE - syslog(LOG_DEBUG, "stat %s.",cmd->filename); + logger->log(LOG_DEBUG,"stat %s.",cmd->filename); #endif int err = ioc->stat(cmd->filename, (struct stat *) resp->payload); diff --git a/src/TruncateTask.cpp b/src/TruncateTask.cpp index f57738307..d28c56ee8 100644 --- a/src/TruncateTask.cpp +++ b/src/TruncateTask.cpp @@ -2,6 +2,7 @@ #include "TruncateTask.h" #include #include "messageFormat.h" +#include "SMLogging.h" using namespace std; @@ -25,6 +26,7 @@ TruncateTask::~TruncateTask() bool TruncateTask::run() { + SMLogging* logger = SMLogging::get(); bool success; uint8_t buf[1024] = {0}; @@ -38,7 +40,7 @@ bool TruncateTask::run() truncate_cmd *cmd = (truncate_cmd *) buf; #ifdef SM_TRACE - syslog(LOG_DEBUG, "truncate %s newlength %i.",cmd->filename,cmd->length); + logger->log(LOG_DEBUG,"truncate %s newlength %i.",cmd->filename,cmd->length); #endif int err = ioc->truncate(cmd->filename, cmd->length); diff --git a/src/UnlinkTask.cpp b/src/UnlinkTask.cpp index c994a2f2e..b027a0bf3 100644 --- a/src/UnlinkTask.cpp +++ b/src/UnlinkTask.cpp @@ -2,6 +2,7 @@ #include "UnlinkTask.h" #include #include "messageFormat.h" +#include "SMLogging.h" using namespace std; @@ -26,6 +27,7 @@ UnlinkTask::~UnlinkTask() bool UnlinkTask::run() { + SMLogging* logger = SMLogging::get(); bool success; uint8_t buf[1024] = {0}; @@ -39,7 +41,7 @@ bool UnlinkTask::run() unlink_cmd *cmd = (unlink_cmd *) buf; #ifdef SM_TRACE - syslog(LOG_DEBUG, "unlink %s.",cmd->filename); + logger->log(LOG_DEBUG,"unlink %s.",cmd->filename); #endif int err = ioc->unlink(cmd->filename); diff --git a/src/WriteTask.cpp b/src/WriteTask.cpp index 47a4246e4..e37f4a3b6 100644 --- a/src/WriteTask.cpp +++ b/src/WriteTask.cpp @@ -2,6 +2,7 @@ #include "WriteTask.h" #include "messageFormat.h" #include "IOCoordinator.h" +#include "SMLogging.h" #include using namespace std; @@ -28,6 +29,7 @@ WriteTask::~WriteTask() bool WriteTask::run() { + SMLogging* logger = SMLogging::get(); bool success; uint8_t cmdbuf[1024] = {0}; @@ -44,7 +46,7 @@ bool WriteTask::run() check_error("WriteTask read", false); #ifdef SM_TRACE - syslog(LOG_DEBUG, "write filename %s offset %i count %i.",cmd->filename,cmd->offset,cmd->count); + logger->log(LOG_DEBUG,"write filename %s offset %i count %i.",cmd->filename,cmd->offset,cmd->count); #endif size_t readCount = 0, writeCount = 0; diff --git a/src/main.cpp b/src/main.cpp index 6f614fbd4..e7d3ea10d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,10 +8,10 @@ #include #include #include -#include using namespace std; +#include "SMLogging.h" #include "SessionManager.h" using namespace storagemanager; @@ -25,18 +25,14 @@ int main(int argc, char** argv) int ret = 0; - //TODO: make this configurable - setlogmask (LOG_UPTO (LOG_DEBUG)); + SMLogging* logger = SMLogging::get(); - openlog ("StorageManager", LOG_PID | LOG_NDELAY, LOG_LOCAL2); - - syslog(LOG_NOTICE, "StorageManager started."); + logger->log(LOG_NOTICE,"StorageManager started."); SessionManager* sm = SessionManager::get(); ret = sm->start(); - closelog (); return ret; }