summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-12-16 20:27:44 +0000
committerChris Wilson <chris+github@qwirx.com>2006-12-16 20:27:44 +0000
commit8b9dbce8c787890b1e74e27a06e3780515c34b65 (patch)
tree36579e572c21283dcb52291c4a2c3b2a25d26317
parenta3c9642a2db8fee585c35da6525be4418f4cc5fd (diff)
Change all logging to use the logging framework, as an example. (refs #3)
-rw-r--r--bin/bbackupd/BackupDaemon.cpp287
-rw-r--r--bin/bbackupd/bbackupd.cpp18
2 files changed, 161 insertions, 144 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 87955fa4..c9b9fb52 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -18,9 +18,6 @@
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
-#ifdef HAVE_SYSLOG_H
- #include <syslog.h>
-#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
@@ -76,6 +73,7 @@
#include "Conversion.h"
#include "Archive.h"
#include "Timer.h"
+#include "Logging.h"
#include "MemLeakFindOn.h"
@@ -224,7 +222,7 @@ void BackupDaemon::SetupInInitialProcess()
// Print a warning on this platform if the CommandSocket is used.
if(GetConfiguration().KeyExists("CommandSocket"))
{
- printf(
+ BOX_WARNING(
"==============================================================================\n"
"SECURITY WARNING: This platform cannot check the credentials of connections to\n"
"the command socket. This is a potential DoS security problem.\n"
@@ -278,29 +276,21 @@ void BackupDaemon::RunHelperThread(void)
}
catch (BoxException &e)
{
- ::syslog(LOG_ERR, "Failed to open command socket: %s",
+ BOX_ERROR("Failed to open command socket" <<
e.what());
SetTerminateWanted();
break; // this is fatal to listening thread
}
- catch (...)
- {
- ::syslog(LOG_ERR, "Failed to open command socket: "
- "unknown error");
- SetTerminateWanted();
- break; // this is fatal to listening thread
- }
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to open command socket: "
- "%s", e.what());
+ BOX_ERROR("Failed to open command socket" <<
+ e.what());
SetTerminateWanted();
break; // this is fatal to listening thread
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to open command socket: "
+ BOX_ERROR("Failed to open command socket: "
"unknown error");
SetTerminateWanted();
break; // this is fatal to listening thread
@@ -313,7 +303,7 @@ void BackupDaemon::RunHelperThread(void)
// This next section comes from Ben's original function
// Log
- ::syslog(LOG_INFO, "Connection from command socket");
+ BOX_INFO("Connection from command socket");
// Send a header line summarising the configuration
// and current state
@@ -337,8 +327,8 @@ void BackupDaemon::RunHelperThread(void)
readLine.GetLine(command) &&
!IsTerminateWanted())
{
- TRACE1("Received command '%s' over "
- "command socket\n", command.c_str());
+ BOX_TRACE("Received command '" << command
+ << "' over command socket");
bool sendOK = false;
bool sendResponse = true;
@@ -379,7 +369,9 @@ void BackupDaemon::RunHelperThread(void)
}
else
{
- ::syslog(LOG_ERR, "Received unknown command '%s' from client", command.c_str());
+ BOX_ERROR("Received unknown command "
+ "'" << command << "' "
+ "from client");
sendResponse = true;
sendOK = false;
}
@@ -404,17 +396,17 @@ void BackupDaemon::RunHelperThread(void)
}
catch(BoxException &e)
{
- ::syslog(LOG_ERR, "Communication error with "
- "control client: %s", e.what());
+ BOX_ERROR("Communication error with "
+ "control client: " << e.what());
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error in command socket "
- "thread: %s", e.what());
+ BOX_ERROR("Internal error in command socket "
+ "thread: " << e.what());
}
catch(...)
{
- ::syslog(LOG_ERR, "Communication error with control client");
+ BOX_ERROR("Communication error with control client");
}
}
}
@@ -473,14 +465,13 @@ void BackupDaemon::Run()
}
catch(std::exception &e)
{
- ::syslog(LOG_WARNING, "Internal error while "
+ BOX_WARNING("Internal error while "
"closing command socket after "
- "another exception: %s", e.what());
+ "another exception: " << e.what());
}
catch(...)
{
- ::syslog(LOG_WARNING,
- "Error closing command socket "
+ BOX_WARNING("Error closing command socket "
"after exception, ignored.");
}
mpCommandSocketInfo = 0;
@@ -674,7 +665,7 @@ void BackupDaemon::Run2()
if(deleteStoreObjectInfoFile &&
!DeleteStoreObjectInfo())
{
- ::syslog(LOG_ERR, "Failed to delete the "
+ BOX_ERROR("Failed to delete the "
"StoreObjectInfoFile, backup cannot "
"continue safely.");
// prevent runaway process where the logs fill up -- without this
@@ -697,7 +688,7 @@ void BackupDaemon::Run2()
{
// Set state and log start
SetState(State_Connected);
- ::syslog(LOG_INFO, "Beginning scan of local files");
+ BOX_INFO("Beginning scan of local files");
std::string extendedLogFile;
if (conf.KeyExists("ExtendedLogFile"))
@@ -810,7 +801,7 @@ void BackupDaemon::Run2()
CommitIDMapsAfterSync();
// Log
- ::syslog(LOG_INFO, "Finished scan of local files");
+ BOX_INFO("Finished scan of local files");
// --------------------------------------------------------------------------------------------
@@ -834,8 +825,8 @@ void BackupDaemon::Run2()
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error during "
- "backup run: %s", e.what());
+ BOX_ERROR("Internal error during "
+ "backup run: " << e.what());
errorOccurred = true;
}
catch(...)
@@ -864,26 +855,28 @@ void BackupDaemon::Run2()
// Handle restart?
if(StopRun())
{
- ::syslog(LOG_INFO, "Exception (%d/%d) due to signal", errorCode, errorSubCode);
+ BOX_INFO("Exception (" << errorCode
+ << "/" << errorSubCode
+ << ") due to signal");
return;
}
// If the Berkely db files get corrupted, delete them and try again immediately
if(isBerkelyDbFailure)
{
- ::syslog(LOG_ERR, "Berkely db inode map files corrupted, deleting and restarting scan. Renamed files and directories will not be tracked until after this scan.\n");
+ BOX_ERROR("Berkely db inode map files corrupted, deleting and restarting scan. Renamed files and directories will not be tracked until after this scan.");
::sleep(1);
}
else
{
// Not restart/terminate, pause and retry
SetState(State_Error);
- ::syslog(LOG_ERR,
- "Exception caught (%s %d/%d), "
- "reset state and waiting "
- "to retry...",
- errorString, errorCode,
- errorSubCode);
+ BOX_ERROR("Exception caught ("
+ << errorString
+ << " " << errorCode
+ << "/" << errorSubCode
+ << "), reset state and "
+ "waiting to retry...");
::sleep(10);
nextSyncTime = currentSyncStartTime +
SecondsToBoxTime(90) +
@@ -894,9 +887,12 @@ void BackupDaemon::Run2()
}
// Log the stats
- ::syslog(LOG_INFO, "File statistics: total file size uploaded %lld, bytes already on server %lld, encoded size %lld",
- BackupStoreFile::msStats.mBytesInEncodedFiles, BackupStoreFile::msStats.mBytesAlreadyOnServer,
- BackupStoreFile::msStats.mTotalFileStreamSize);
+ BOX_INFO("File statistics: total file size uploaded "
+ << BackupStoreFile::msStats.mBytesInEncodedFiles
+ << ", bytes already on server "
+ << BackupStoreFile::msStats.mBytesAlreadyOnServer
+ << ", encoded size "
+ << BackupStoreFile::msStats.mTotalFileStreamSize);
BackupStoreFile::ResetStats();
// Tell anything connected to the command socket
@@ -966,29 +962,32 @@ int BackupDaemon::UseScriptToSeeIfSyncAllowed()
}
catch(ConversionException &e)
{
- ::syslog(LOG_ERR, "Invalid output "
- "from SyncAllowScript '%s': "
- "'%s'",
- conf.GetKeyValue("SyncAllowScript").c_str(),
- line.c_str());
+ BOX_ERROR("Invalid output "
+ "from SyncAllowScript '"
+ << conf.GetKeyValue("SyncAllowScript")
+ << "': '" << line << "'");
throw;
}
- ::syslog(LOG_INFO, "Delaying sync by %d seconds (SyncAllowScript '%s')", waitInSeconds, conf.GetKeyValue("SyncAllowScript").c_str());
+ BOX_INFO("Delaying sync by " << waitInSeconds
+ << " seconds (SyncAllowScript '"
+ << conf.GetKeyValue("SyncAllowScript")
+ << "')");
}
}
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error running SyncAllowScript: "
- "%s", e.what());
+ BOX_ERROR("Internal error running SyncAllowScript: "
+ << e.what());
}
catch(...)
{
// Ignore any exceptions
// Log that something bad happened
- ::syslog(LOG_ERR, "Error running SyncAllowScript '%s'", conf.GetKeyValue("SyncAllowScript").c_str());
+ BOX_ERROR("Error running SyncAllowScript '"
+ << conf.GetKeyValue("SyncAllowScript") << "'");
}
// Wait and then cleanup child process, if any
@@ -1040,7 +1039,7 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla
ASSERT(mpCommandSocketInfo != 0);
if(mpCommandSocketInfo == 0) {::sleep(1); return;} // failure case isn't too bad
- TRACE1("Wait on command socket, delay = %lld\n", RequiredDelay);
+ BOX_TRACE("Wait on command socket, delay = " << RequiredDelay);
try
{
@@ -1066,7 +1065,7 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla
{
#ifdef PLATFORM_CANNOT_FIND_PEER_UID_OF_UNIX_SOCKET
bool uidOK = true;
- ::syslog(LOG_WARNING, "On this platform, no security check can be made on the credentials of peers connecting to the command socket. (bbackupctl)");
+ BOX_WARNING("On this platform, no security check can be made on the credentials of peers connecting to the command socket. (bbackupctl)");
#else
// Security check -- does the process connecting to this socket have
// the same UID as this process?
@@ -1091,14 +1090,14 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla
if(!uidOK)
{
// Dump the connection
- ::syslog(LOG_ERR, "Incoming command connection from peer had different user ID than this process, or security check could not be completed.");
+ BOX_ERROR("Incoming command connection from peer had different user ID than this process, or security check could not be completed.");
mpCommandSocketInfo->mpConnectedSocket.reset();
return;
}
else
{
// Log
- ::syslog(LOG_INFO, "Connection from command socket");
+ BOX_INFO("Connection from command socket");
// Send a header line summarising the configuration and current state
const Configuration &conf(GetConfiguration());
@@ -1136,7 +1135,8 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla
while(mpCommandSocketInfo->mpGetLine != 0 && !mpCommandSocketInfo->mpGetLine->IsEOF()
&& mpCommandSocketInfo->mpGetLine->GetLine(command, false /* no preprocessing */, timeout))
{
- TRACE1("Receiving command '%s' over command socket\n", command.c_str());
+ BOX_TRACE("Receiving command '" << command
+ << "' over command socket");
bool sendOK = false;
bool sendResponse = true;
@@ -1193,8 +1193,8 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error in command socket thread: "
- "%s", e.what());
+ BOX_ERROR("Internal error in command socket thread: "
+ << e.what());
// If an error occurs, and there is a connection active, just close that
// connection and continue. Otherwise, let the error propagate.
if(mpCommandSocketInfo->mpConnectedSocket.get() == 0)
@@ -1238,7 +1238,7 @@ void BackupDaemon::CloseCommandConnection()
#ifndef WIN32
try
{
- TRACE0("Closing command connection\n");
+ BOX_TRACE("Closing command connection");
if(mpCommandSocketInfo->mpGetLine)
{
@@ -1249,8 +1249,8 @@ void BackupDaemon::CloseCommandConnection()
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error while closing command "
- "socket: %s", e.what());
+ BOX_ERROR("Internal error while closing command "
+ "socket: " << e.what());
}
catch(...)
{
@@ -1299,8 +1299,8 @@ void BackupDaemon::SendSyncStartOrFinish(bool SendStart)
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error while sending to "
- "command socket client: %s", e.what());
+ BOX_ERROR("Internal error while sending to "
+ "command socket client: " << e.what());
CloseCommandConnection();
}
catch(...)
@@ -1403,7 +1403,7 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
struct mntent *entry = 0;
while((entry = ::getmntent(mountPointsFile)) != 0)
{
- TRACE1("Found mount point at %s\n", entry->mnt_dir);
+ BOX_TRACE("Found mount point at " << entry->mnt_dir);
mountPoints.insert(std::string(entry->mnt_dir));
}
@@ -1425,12 +1425,11 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
try
{
-
// Read all the entries, and put them in the set
struct mnttab entry;
while(getmntent(mountPointsFile, &entry) == 0)
{
- TRACE1("Found mount point at %s\n", entry.mnt_mountp);
+ BOX_TRACE("Found mount point at " << entry.mnt_mountp);
mountPoints.insert(std::string(entry.mnt_mountp));
}
@@ -1459,7 +1458,7 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
for(std::list<std::pair<std::string, Configuration> >::const_iterator i = rLocationsConf.mSubConfigurations.begin();
i != rLocationsConf.mSubConfigurations.end(); ++i)
{
-TRACE0("new location\n");
+ BOX_TRACE("new location");
// Create a record for it
Location *ploc = new Location;
try
@@ -1497,19 +1496,22 @@ TRACE0("new location\n");
// Warn in logs if the directory isn't absolute
if(ploc->mPath[0] != '/')
{
- ::syslog(LOG_ERR, "Location path '%s' isn't absolute", ploc->mPath.c_str());
+ BOX_WARNING("Location path '"
+ << ploc->mPath
+ << "' is not absolute");
}
// Go through the mount points found, and find a suitable one
std::string mountName("/");
{
std::set<std::string, mntLenCompare>::const_iterator i(mountPoints.begin());
- TRACE1("%d potential mount points\n", mountPoints.size());
+ BOX_TRACE(mountPoints.size()
+ << " potential mount points");
for(; i != mountPoints.end(); ++i)
{
// Compare first n characters with the filename
// If it matches, the file belongs in that mount point
// (sorting order ensures this)
- TRACE1("checking against mount point %s\n", i->c_str());
+ BOX_TRACE("checking against mount point " << *i);
if(::strncmp(i->c_str(), ploc->mPath.c_str(), i->size()) == 0)
{
// Match
@@ -1517,7 +1519,9 @@ TRACE0("new location\n");
break;
}
}
- TRACE2("mount point chosen for %s is %s\n", ploc->mPath.c_str(), mountName.c_str());
+ BOX_TRACE("mount point chosen for "
+ << ploc->mPath << " is "
+ << mountName);
}
#endif
@@ -1571,8 +1575,9 @@ TRACE0("new location\n");
}
catch (BoxException &e)
{
- ::syslog(LOG_ERR, "Failed to get attributes for path "
- "'%s', skipping.", ploc->mPath.c_str());
+ BOX_ERROR("Failed to get attributes "
+ "for path '" << ploc->mPath
+ << "', skipping.");
continue;
}
@@ -1598,8 +1603,9 @@ TRACE0("new location\n");
{
delete ploc;
ploc = 0;
- ::syslog(LOG_ERR, "Failed to setup location '%s' path '%s'",
- ploc->mName.c_str(), ploc->mPath.c_str());
+ BOX_ERROR("Failed to setup location '"
+ << ploc->mName << "' path '"
+ << ploc->mPath << "'");
throw;
}
}
@@ -1607,8 +1613,10 @@ TRACE0("new location\n");
// Any entries in the root directory which need deleting?
if(dir.GetNumberOfEntries() > 0)
{
- ::syslog(LOG_INFO, "%d redundant locations in root directory found, will delete from store after %d seconds.",
- dir.GetNumberOfEntries(), BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER);
+ BOX_INFO(dir.GetNumberOfEntries() << " redundant locations "
+ "in root directory found, will delete from store "
+ "after " << BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER
+ << " seconds.");
// Store directories in list of things to delete
mUnusedRootDirEntries.clear();
@@ -1621,7 +1629,7 @@ TRACE0("new location\n");
const std::string &name(clear.GetClearFilename());
mUnusedRootDirEntries.push_back(std::pair<int64_t,std::string>(en->GetObjectID(), name));
// Log this
- ::syslog(LOG_INFO, "Unused location in root: %s", name.c_str());
+ BOX_INFO("Unused location in root: " << name);
}
ASSERT(mUnusedRootDirEntries.size() > 0);
// Time to delete them
@@ -1738,14 +1746,14 @@ void BackupDaemon::DeleteCorruptBerkelyDbFiles()
MakeMapBaseName(l, filename);
// Delete the file
- TRACE1("Deleting %s\n", filename.c_str());
+ BOX_TRACE("Deleting " << filename);
::unlink(filename.c_str());
// Add a suffix for the new map
filename += ".n";
// Delete that too
- TRACE1("Deleting %s\n", filename.c_str());
+ BOX_TRACE("Deleting " << filename);
::unlink(filename.c_str());
}
}
@@ -1825,10 +1833,9 @@ void BackupDaemon::CommitIDMapsAfterSync()
#endif
if(::rename(newmap.c_str(), target.c_str()) != 0)
{
- ::syslog(LOG_ERR, "failed to rename ID map: "
- "%s to %s: %s",
- newmap.c_str(), target.c_str(),
- strerror(errno));
+ BOX_ERROR("failed to rename ID map: " << newmap
+ << " to " << target << ": "
+ << strerror(errno));
THROW_EXCEPTION(CommonException, OSFileError)
}
}
@@ -1931,8 +1938,8 @@ void BackupDaemon::SetState(int State)
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error while writing state "
- "to command socket: %s", e.what());
+ BOX_ERROR("Internal error while writing state "
+ "to command socket: " << e.what());
CloseCommandConnection();
}
catch(...)
@@ -1950,8 +1957,8 @@ void BackupDaemon::SetState(int State)
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error while writing state "
- "to command socket: %s", e.what());
+ BOX_ERROR("Internal error while writing state "
+ "to command socket: " << e.what());
CloseCommandConnection();
}
catch(...)
@@ -1996,7 +2003,7 @@ void BackupDaemon::NotifySysadmin(int Event)
{
static const char *sEventNames[] = {"store-full", "read-error", 0};
- TRACE1("BackupDaemon::NotifySysadmin() called, event = %d\n", Event);
+ BOX_TRACE("BackupDaemon::NotifySysadmin() called, event = " << Event);
if(Event < 0 || Event > NotifyEvent__MAX)
{
@@ -2014,7 +2021,9 @@ void BackupDaemon::NotifySysadmin(int Event)
if(!conf.KeyExists("NotifyScript"))
{
// Log, and then return
- ::syslog(LOG_ERR, "Not notifying administrator about event %s -- set NotifyScript to do this in future", sEventNames[Event]);
+ BOX_ERROR("Not notifying administrator about event "
+ << sEventNames[Event] << " -- set NotifyScript "
+ "to do this in future");
return;
}
@@ -2022,12 +2031,15 @@ void BackupDaemon::NotifySysadmin(int Event)
std::string script(conf.GetKeyValue("NotifyScript") + ' ' + sEventNames[Event]);
// Log what we're about to do
- ::syslog(LOG_INFO, "About to notify administrator about event %s, running script '%s'", sEventNames[Event], script.c_str());
+ BOX_INFO("About to notify administrator about event "
+ << sEventNames[Event] << ", running script '"
+ << script << "'");
// Then do it
if(::system(script.c_str()) != 0)
{
- ::syslog(LOG_ERR, "Notify script returned an error code. ('%s')", script.c_str());
+ BOX_ERROR("Notify script returned an error code. ('"
+ << script << "')");
}
// Flag that this is done so the administrator isn't constantly bombarded with lots of errors
@@ -2059,14 +2071,15 @@ void BackupDaemon::DeleteUnusedRootDirEntries(BackupClientContext &rContext)
}
// Entries to delete, and it's the right time to do so...
- ::syslog(LOG_INFO, "Deleting unused locations from store root...");
+ BOX_INFO("Deleting unused locations from store root...");
BackupProtocolClient &connection(rContext.GetConnection());
for(std::vector<std::pair<int64_t,std::string> >::iterator i(mUnusedRootDirEntries.begin()); i != mUnusedRootDirEntries.end(); ++i)
{
connection.QueryDeleteDirectory(i->first);
// Log this
- ::syslog(LOG_INFO, "Deleted %s (ID %08llx) from store root", i->second.c_str(), i->first);
+ BOX_INFO("Deleted " << i->second << " (ID " << i->first
+ << ") from store root");
}
// Reset state
@@ -2406,20 +2419,20 @@ bool BackupDaemon::SerializeStoreObjectInfo(int64_t aClientStoreMarker, box_time
//
//
aFile.Close();
- ::syslog(LOG_INFO, "Saved store object info file '%s'",
- StoreObjectInfoFile.c_str());
+ BOX_INFO("Saved store object info file: "
+ << StoreObjectInfoFile);
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error writing store object "
- "info file (%s): %s",
- StoreObjectInfoFile.c_str(), e.what());
+ BOX_ERROR("Internal error writing store object "
+ "info file (" << StoreObjectInfoFile << "): "
+ << e.what());
}
catch(...)
{
- ::syslog(LOG_ERR, "Internal error writing store object "
- "info file (%s): unknown error",
- StoreObjectInfoFile.c_str());
+ BOX_ERROR("Internal error writing store object "
+ "info file (" << StoreObjectInfoFile << "): "
+ "unknown error");
}
return created;
@@ -2470,10 +2483,10 @@ bool BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_
if(iMagicValue != STOREOBJECTINFO_MAGIC_ID_VALUE)
{
- ::syslog(LOG_WARNING, "Store object info file '%s' "
+ BOX_WARNING("Store object info file "
"is not a valid or compatible serialised "
- "archive. Will re-cache from store.",
- StoreObjectInfoFile.c_str());
+ "archive. Will re-cache from store. "
+ "(" << StoreObjectInfoFile << ")");
return false;
}
@@ -2485,10 +2498,10 @@ bool BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_
if(strMagicValue != STOREOBJECTINFO_MAGIC_ID_STRING)
{
- ::syslog(LOG_WARNING, "Store object info file '%s' "
+ BOX_WARNING("Store object info file "
"is not a valid or compatible serialised "
- "archive. Will re-cache from store.",
- StoreObjectInfoFile.c_str());
+ "archive. Will re-cache from store. "
+ "(" << StoreObjectInfoFile << ")");
return false;
}
@@ -2501,11 +2514,10 @@ bool BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_
if(iVersion != STOREOBJECTINFO_VERSION)
{
- ::syslog(LOG_WARNING, "Store object info file '%s' "
- "version %d unsupported. "
- "Will re-cache from store.",
- StoreObjectInfoFile.c_str(),
- iVersion);
+ BOX_WARNING("Store object info file "
+ "version " << iVersion << " unsupported. "
+ "Will re-cache from store. "
+ "(" << StoreObjectInfoFile << ")");
return false;
}
@@ -2518,9 +2530,9 @@ bool BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_
if(lastKnownConfigModTime != GetLoadedConfigModifiedTime())
{
- ::syslog(LOG_WARNING, "Store object info file '%s' "
- "out of date. Will re-cache from store",
- StoreObjectInfoFile.c_str());
+ BOX_WARNING("Store object info file "
+ "out of date. Will re-cache from store. "
+ "(" << StoreObjectInfoFile << ")");
return false;
}
@@ -2567,23 +2579,20 @@ bool BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_
//
//
aFile.Close();
- ::syslog(LOG_INFO, "Loaded store object info file '%s', "
- "version [%d]", StoreObjectInfoFile.c_str(),
- iVersion);
-
+ BOX_INFO("Loaded store object info file version " << iVersion
+ << "(" << StoreObjectInfoFile << ")");
+
return true;
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Internal error reading store object "
- "info file (%s): %s",
- StoreObjectInfoFile.c_str(), e.what());
+ BOX_ERROR("Internal error reading store object info file: "
+ << StoreObjectInfoFile << ": " << e.what());
}
catch(...)
{
- ::syslog(LOG_ERR, "Internal error reading store object "
- "info file (%s): unknown error",
- StoreObjectInfoFile.c_str());
+ BOX_ERROR("Internal error reading store object info file: "
+ << StoreObjectInfoFile << ": unknown error");
}
DeleteAllLocations();
@@ -2592,11 +2601,10 @@ bool BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_
theLastSyncTime = 0;
theNextSyncTime = 0;
- ::syslog(LOG_WARNING, "Requested store object info file '%s' "
- "does not exist, not accessible, or inconsistent. "
- "Will re-cache from store.",
- StoreObjectInfoFile.c_str());
-
+ BOX_WARNING("Store object info file is missing, not accessible, "
+ "or inconsistent. Will re-cache from store. "
+ "(" << StoreObjectInfoFile << ")");
+
return false;
}
@@ -2624,9 +2632,9 @@ bool BackupDaemon::DeleteStoreObjectInfo() const
if(!FileExists(storeObjectInfoFile.c_str()))
{
// File doesn't exist -- so can't be deleted. But something isn't quite right, so log a message
- ::syslog(LOG_ERR, "Expected to be able to delete "
- "store object info file '%s', but the file did not exist.",
- storeObjectInfoFile.c_str());
+ BOX_WARNING("Store object info file did not exist when it "
+ "was supposed to. (" << storeObjectInfoFile << ")");
+
// Return true to stop things going around in a loop
return true;
}
@@ -2634,9 +2642,8 @@ bool BackupDaemon::DeleteStoreObjectInfo() const
// Actually delete it
if(::unlink(storeObjectInfoFile.c_str()) != 0)
{
- ::syslog(LOG_ERR, "Failed to delete the old "
- "store object info file '%s': %s",
- storeObjectInfoFile.c_str(), strerror(errno));
+ BOX_ERROR("Failed to delete the old store object info file: "
+ << storeObjectInfoFile << ": "<< strerror(errno));
return false;
}
diff --git a/bin/bbackupd/bbackupd.cpp b/bin/bbackupd/bbackupd.cpp
index e00d3628..1ddbf397 100644
--- a/bin/bbackupd/bbackupd.cpp
+++ b/bin/bbackupd/bbackupd.cpp
@@ -12,6 +12,7 @@
#include "MainHelper.h"
#include "BoxPortsAndFiles.h"
#include "BackupStoreException.h"
+#include "Logging.h"
#include "MemLeakFindOn.h"
@@ -26,9 +27,17 @@ int main(int argc, const char *argv[])
{
MAINHELPER_START
-#ifdef WIN32
+ Logging::SetProgramName("Box Backup (bbackupd)");
+ Logging::ToConsole(true);
+ Logging::FilterSyslog (Log::EVERYTHING);
- ::openlog("Box Backup (bbackupd)", LOG_PID, LOG_LOCAL6);
+ #ifdef NDEBUG
+ Logging::FilterConsole(Log::INFO);
+ #else
+ Logging::FilterConsole(Log::EVERYTHING);
+ #endif
+
+#ifdef WIN32
if(argc == 2 &&
(::strcmp(argv[1], "--help") == 0 ||
@@ -56,6 +65,7 @@ int main(int argc, const char *argv[])
if (argc >= 2 && ::strcmp(argv[1], "--service") == 0)
{
runAsWin32Service = true;
+ Logging::ToSyslog(true);
}
gpDaemonService = new Win32BackupService();
@@ -66,7 +76,7 @@ int main(int argc, const char *argv[])
if (runAsWin32Service)
{
- syslog(LOG_INFO, "Box Backup service starting");
+ BOX_INFO("Box Backup service starting");
char* config = NULL;
if (argc >= 3)
@@ -81,7 +91,7 @@ int main(int argc, const char *argv[])
free(config);
}
- syslog(LOG_INFO, "Box Backup service shut down");
+ BOX_INFO("Box Backup service shut down");
}
else
{