Changeset 1784

Show
Ignore:
Timestamp:
01/08/2007 00:18:50 (18 months ago)
Author:
chris
Message:

Replace almost all calls to syslog() with logging framework. (merges [1783])

Location:
box/chris/general
Files:
21 modified

Legend:

Unmodified
Added
Removed
  • box/chris/general/bin/bbackupctl/bbackupctl.cpp

    r1690 r1784  
    163163 
    164164#if defined WIN32 && ! defined NDEBUG 
    165                 syslog(LOG_ERR,"Failed to connect to the command socket"); 
     165                BOX_ERROR("Failed to connect to the command socket"); 
    166166#endif 
    167167 
     
    176176        if(!getLine.GetLine(configSummary)) 
    177177        { 
    178 #if defined WIN32 && ! defined NDEBUG 
    179                 syslog(LOG_ERR, "Failed to receive configuration summary " 
     178                BOX_ERROR("Failed to receive configuration summary " 
    180179                        "from daemon"); 
    181 #else 
    182                 printf("Failed to receive configuration summary from daemon\n"); 
    183 #endif 
    184  
    185180                return 1; 
    186181        } 
     
    189184        if(getLine.IsEOF()) 
    190185        { 
    191 #if defined WIN32 && ! defined NDEBUG 
    192                 syslog(LOG_ERR, "Server rejected the connection. " 
    193                         "Are you running bbackupctl as the same user " 
    194                         "as the daemon?"); 
    195 #else 
    196                 printf("Server rejected the connection. " 
    197                         "Are you running bbackupctl as the same user " 
    198                         "as the daemon?\n"); 
    199 #endif 
    200  
     186                BOX_ERROR("Server rejected the connection. Are you running " 
     187                        "bbackupctl as the same user as the daemon?"); 
    201188                return 1; 
    202189        } 
     
    225212        if(!getLine.GetLine(stateLine) || getLine.IsEOF()) 
    226213        { 
    227 #if defined WIN32 && ! defined NDEBUG 
    228                 syslog(LOG_ERR, "Failed to receive state line from daemon"); 
    229 #else 
    230                 printf("Failed to receive state line from daemon\n"); 
    231 #endif 
     214                BOX_ERROR("Failed to receive state line from daemon"); 
    232215                return 1; 
    233216        } 
     
    237220        if(::sscanf(stateLine.c_str(), "state %d", &currentState) != 1) 
    238221        { 
    239                 printf("State line didn't decode\n"); 
     222                BOX_ERROR("Received invalid state line from daemon"); 
    240223                return 1; 
    241224        } 
     
    267250                        if(!autoBackup) 
    268251                        { 
    269                                 printf("ERROR: Daemon is not in automatic mode -- " 
    270                                         "sync will never start!\n"); 
     252                                BOX_ERROR("Daemon is not in automatic mode, " 
     253                                        "sync will never start!"); 
    271254                                return 1; 
    272255                        } 
  • box/chris/general/bin/bbackupd/BackupClientContext.cpp

    r1659 r1784  
    1010#include "Box.h" 
    1111 
    12 #ifdef HAVE_SYSLOG_H 
    13         #include <syslog.h> 
    14 #endif 
    1512#ifdef HAVE_SIGNAL_H 
    1613        #include <signal.h> 
    1714#endif 
     15 
    1816#ifdef HAVE_SYS_TIME_H 
    1917        #include <sys/time.h> 
     
    128126                 
    129127                // Log intention 
    130                 ::syslog(LOG_INFO, "Opening connection to server %s...", mHostname.c_str()); 
     128                BOX_INFO("Opening connection to server '" << 
     129                        mHostname << "'..."); 
    131130 
    132131                // Connect! 
     
    148147                        if (!mpExtendedLogFileHandle) 
    149148                        { 
    150                                 ::syslog(LOG_ERR, "Failed to open extended " 
    151                                         "log file: %s", strerror(errno)); 
     149                                BOX_ERROR("Failed to open extended log " 
     150                                        "file: " << strerror(errno)); 
    152151                        } 
    153152                        else 
     
    195194                 
    196195                // Log success 
    197                 ::syslog(LOG_INFO, "Connection made, login successful"); 
     196                BOX_INFO("Connection made, login successful"); 
    198197 
    199198                // Check to see if there is any space available on the server 
     
    203202                        mStorageLimitExceeded = true; 
    204203                        // Log 
    205                         ::syslog(LOG_WARNING, "Exceeded storage hard-limit on server -- not uploading changes to files"); 
     204                        BOX_WARNING("Exceeded storage hard-limit on server, " 
     205                                "not uploading changes to files"); 
    206206                } 
    207207        } 
  • box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp

    r1033 r1784  
    4545        memset(buf, 0, sizeof(buf)); 
    4646        _snprintf(buf, sizeof(buf)-1, "%s (%d)", s, err); 
    47         ::syslog(LOG_ERR, "%s", buf); 
     47        BOX_ERROR(buf); 
    4848        MessageBox(0, buf, "Error",  
    4949                MB_OK | MB_SETFOREGROUND | MB_DEFAULT_DESKTOP_ONLY); 
     
    192192                if (emu_stat(pConfigFileName, &st) != 0) 
    193193                { 
    194                         syslog(LOG_ERR, "Failed to open configuration file: " 
    195                                 "%s: %s", pConfigFileName, strerror(errno)); 
     194                        BOX_ERROR("Failed to open configuration file '" << 
     195                                pConfigFileName << "': " << strerror(errno)); 
    196196                        return 1; 
    197197                } 
     
    200200                { 
    201201         
    202                         syslog(LOG_ERR, "Failed to open configuration file: " 
    203                                 "%s: not a file", pConfigFileName); 
     202                        BOX_ERROR("Failed to open configuration file '" << 
     203                                pConfigFileName << "': not a file"); 
    204204                        return 1; 
    205205                } 
     
    210210        if (!scm)  
    211211        { 
    212                 syslog(LOG_ERR, "Failed to open service control manager: " 
    213                         "error %d", GetLastError()); 
     212                BOX_ERROR("Failed to open service control manager: " << 
     213                        GetErrorMessage(GetLastError())); 
    214214                return 1; 
    215215        } 
     
    249249                        case ERROR_SERVICE_EXISTS: 
    250250                        { 
    251                                 ::syslog(LOG_ERR, "Failed to create Box Backup " 
     251                                BOX_ERROR("Failed to create Box Backup " 
    252252                                        "service: it already exists"); 
    253253                        } 
     
    256256                        case ERROR_SERVICE_MARKED_FOR_DELETE: 
    257257                        { 
    258                                 ::syslog(LOG_ERR, "Failed to create Box Backup " 
     258                                BOX_ERROR("Failed to create Box Backup " 
    259259                                        "service: it is waiting to be deleted"); 
    260260                        } 
     
    263263                        case ERROR_DUPLICATE_SERVICE_NAME: 
    264264                        { 
    265                                 ::syslog(LOG_ERR, "Failed to create Box Backup " 
     265                                BOX_ERROR("Failed to create Box Backup " 
    266266                                        "service: a service with this name " 
    267267                                        "already exists"); 
     
    271271                        default: 
    272272                        { 
    273                                 ::syslog(LOG_ERR, "Failed to create Box Backup " 
    274                                         "service: error %d", err); 
     273                                BOX_ERROR("Failed to create Box Backup " 
     274                                        "service: error " << 
     275                                        GetErrorMessage(GetLastError())); 
    275276                        } 
    276277                } 
     
    279280        } 
    280281 
    281         ::syslog(LOG_INFO, "Created Box Backup service"); 
     282        BOX_INFO("Created Box Backup service"); 
    282283         
    283284        SERVICE_DESCRIPTION desc; 
     
    287288                &desc)) 
    288289        { 
    289                 ::syslog(LOG_WARNING, "Failed to set description for " 
    290                         "Box Backup service: error %d", GetLastError()); 
     290                BOX_WARNING("Failed to set description for Box Backup " 
     291                        "service: " << GetErrorMessage(GetLastError())); 
    291292        } 
    292293 
     
    302303        if (!scm)  
    303304        { 
    304                 syslog(LOG_ERR, "Failed to open service control manager: " 
    305                         "error %d", GetLastError()); 
     305                BOX_ERROR("Failed to open service control manager: " << 
     306                        GetErrorMessage(GetLastError())); 
    306307                return 1; 
    307308        } 
     
    318319                        // hello microsoft? anyone home? 
    319320                { 
    320                         syslog(LOG_ERR, "Failed to open Box Backup service: " 
     321                        BOX_ERROR("Failed to open Box Backup service: " 
    321322                                "not installed or not found"); 
    322323                } 
    323324                else 
    324325                { 
    325                         syslog(LOG_ERR, "Failed to open Box Backup service: " 
    326                                 "error %d", err); 
     326                        BOX_ERROR("Failed to open Box Backup service: " << 
     327                                GetErrorMessage(err)); 
    327328                } 
    328329                return 1; 
     
    335336                if (err != ERROR_SERVICE_NOT_ACTIVE) 
    336337                { 
    337                         syslog(LOG_WARNING, "Failed to stop Box Backup " 
    338                                 "service: error %d", err); 
     338                        BOX_WARNING("Failed to stop Box Backup service: " << 
     339                                GetErrorMessage(err)); 
    339340                } 
    340341        } 
     
    346347        if (deleted) 
    347348        { 
    348                 syslog(LOG_INFO, "Box Backup service deleted"); 
     349                BOX_INFO("Box Backup service deleted"); 
    349350                return 0; 
    350351        } 
    351352        else if (err == ERROR_SERVICE_MARKED_FOR_DELETE) 
    352353        { 
    353                 syslog(LOG_ERR, "Failed to remove Box Backup service: " 
     354                BOX_ERROR("Failed to remove Box Backup service: " 
    354355                        "it is already being deleted"); 
    355356        } 
    356357        else 
    357358        { 
    358                 syslog(LOG_ERR, "Failed to remove Box Backup service: " 
    359                         "error %d", err); 
     359                BOX_ERROR("Failed to remove Box Backup service: " << 
     360                        GetErrorMessage(err)); 
    360361        } 
    361362 
  • box/chris/general/bin/bbackupquery/BackupQueries.cpp

    r1639 r1784  
    20102010                        opts['r'] /* resume? */); 
    20112011        } 
    2012         catch (BoxException &e) 
    2013         { 
    2014                 ::syslog(LOG_ERR, "Failed to restore: %s", e.what()); 
    2015                 return; 
    2016         } 
    20172012        catch(std::exception &e) 
    20182013        { 
    2019                 ::syslog(LOG_ERR, "Failed to restore: %s", e.what()); 
     2014                BOX_ERROR("Failed to restore: " << e.what()); 
    20202015                return; 
    20212016        } 
    20222017        catch(...) 
    20232018        { 
    2024                 ::syslog(LOG_ERR, "Failed to restore: unknown error"); 
     2019                BOX_ERROR("Failed to restore: unknown exception"); 
    20252020                return; 
    20262021        } 
  • box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp

    r1382 r1784  
    1111 
    1212#include <stdio.h> 
    13  
    14 #ifdef HAVE_SYSLOG_H 
    15         #include <syslog.h> 
    16 #endif 
    1713 
    1814#include "BackupStoreDaemon.h" 
     
    8379        // Store the time 
    8480        mLastHousekeepingRun = timeNow; 
    85         ::syslog(LOG_INFO, "Starting housekeeping"); 
     81        BOX_INFO("Starting housekeeping"); 
    8682 
    8783        // Get the list of accounts 
     
    113109                catch(BoxException &e) 
    114110                { 
    115                         ::syslog(LOG_ERR, "while housekeeping account %08X, exception %s (%d/%d) -- aborting housekeeping run for this account", 
    116                                 *i, e.what(), e.GetType(), e.GetSubType()); 
     111                        BOX_ERROR("Housekeeping on account " << 
     112                                BOX_FORMAT_ACCOUNT(*i) << " threw exception, " 
     113                                "aborting run for this account: " << 
     114                                e.what() << " (" << 
     115                                e.GetType() << "/" << e.GetSubType() << ")"); 
    117116                } 
    118117                catch(std::exception &e) 
    119118                { 
    120                         ::syslog(LOG_ERR, "while housekeeping account %08X, exception %s -- aborting housekeeping run for this account", 
    121                                 *i, e.what()); 
     119                        BOX_ERROR("Housekeeping on account " << 
     120                                BOX_FORMAT_ACCOUNT(*i) << " threw exception, " 
     121                                "aborting run for this account: " << 
     122                                e.what()); 
    122123                } 
    123124                catch(...) 
    124125                { 
    125                         ::syslog(LOG_ERR, "while housekeeping account %08X, unknown exception -- aborting housekeeping run for this account", 
    126                                 *i); 
     126                        BOX_ERROR("Housekeeping on account " << 
     127                                BOX_FORMAT_ACCOUNT(*i) << " threw exception, " 
     128                                "aborting run for this account: " 
     129                                "unknown exception"); 
    127130                } 
    128131         
     
    145148        } 
    146149                 
    147         ::syslog(LOG_INFO, "Finished housekeeping"); 
     150        BOX_INFO("Finished housekeeping"); 
    148151 
    149152        // Placed here for accuracy, if StopRun() is true, for example. 
     
    191194        if(mInterProcessComms.GetLine(line, false /* no pre-processing */, MaximumWaitTime)) 
    192195        { 
    193                 TRACE1("housekeeping received command '%s' over interprocess comms\n", line.c_str()); 
     196                TRACE1("Housekeeping received command '%s' over interprocess comms\n", line.c_str()); 
    194197         
    195198                int account = 0; 
     
    213216                        { 
    214217                                // Yes! -- need to stop now so when it retries to get the lock, it will succeed 
    215                                 ::syslog(LOG_INFO, "Housekeeping giving way to connection for account 0x%08x", AccountNum); 
     218                                BOX_INFO("Housekeeping on account " << 
     219                                        BOX_FORMAT_ACCOUNT(AccountNum) << 
     220                                        "giving way to client connection"); 
    216221                                return true; 
    217222                        } 
  • box/chris/general/bin/bbstored/BackupCommands.cpp

    r1333 r1784  
    99 
    1010#include "Box.h" 
    11  
    12 #ifdef HAVE_SYSLOG_H 
    13 #include <syslog.h> 
    14 #endif 
    1511 
    1612#include <set> 
     
    8985        // Check given client ID against the ID in the certificate certificate 
    9086        // and that the client actually has an account on this machine 
    91         if(mClientID != rContext.GetClientID() || !rContext.GetClientHasAccount()) 
    92         { 
    93                 ::syslog(LOG_INFO, "Failed login: Client ID presented was %08X", mClientID); 
    94                 return std::auto_ptr<ProtocolObject>(new BackupProtocolServerError( 
    95                         BackupProtocolServerError::ErrorType, BackupProtocolServerError::Err_BadLogin)); 
     87        if(mClientID != rContext.GetClientID()) 
     88        { 
     89                BOX_WARNING("Failed login from client ID " <<  
     90                        BOX_FORMAT_ACCOUNT(mClientID) << 
     91                        ": wrong certificate for this account"); 
     92                return std::auto_ptr<ProtocolObject>( 
     93                        new BackupProtocolServerError( 
     94                                BackupProtocolServerError::ErrorType, 
     95                                BackupProtocolServerError::Err_BadLogin)); 
     96        } 
     97 
     98        if(!rContext.GetClientHasAccount()) 
     99        { 
     100                BOX_WARNING("Failed login from client ID " <<  
     101                        BOX_FORMAT_ACCOUNT(mClientID) << 
     102                        ": no such account on this server"); 
     103                return std::auto_ptr<ProtocolObject>( 
     104                        new BackupProtocolServerError( 
     105                                BackupProtocolServerError::ErrorType, 
     106                                BackupProtocolServerError::Err_BadLogin)); 
    96107        } 
    97108 
     
    102113                if(!rContext.AttemptToGetWriteLock()) 
    103114                { 
    104                         ::syslog(LOG_INFO, "Failed to get write lock (for Client ID %08X)", mClientID); 
    105                         return std::auto_ptr<ProtocolObject>(new BackupProtocolServerError( 
    106                                 BackupProtocolServerError::ErrorType, BackupProtocolServerError::Err_CannotLockStoreForWriting));                        
     115                        BOX_WARNING("Failed to get write lock for Client ID " << 
     116                                BOX_FORMAT_ACCOUNT(mClientID)); 
     117                        return std::auto_ptr<ProtocolObject>( 
     118                                new BackupProtocolServerError( 
     119                                        BackupProtocolServerError::ErrorType, 
     120                                        BackupProtocolServerError::Err_CannotLockStoreForWriting));                      
    107121                } 
    108122                 
     
    121135         
    122136        // Log login 
    123         ::syslog(LOG_INFO, "Login: Client ID %08X, %s", mClientID, ((mFlags & Flags_ReadOnly) != Flags_ReadOnly)?"Read/Write":"Read-only"); 
     137        BOX_NOTICE("Login from Client ID " <<  
     138                BOX_FORMAT_ACCOUNT(mClientID) << 
     139                " " << 
     140                (((mFlags & Flags_ReadOnly) != Flags_ReadOnly) 
     141                ?"Read/Write":"Read-only")); 
    124142 
    125143        // Get the usage info for reporting to the client 
     
    141159std::auto_ptr<ProtocolObject> BackupProtocolServerFinished::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext) 
    142160{ 
    143         ::syslog(LOG_INFO, "Session finished"); 
     161        BOX_NOTICE("Session finished for Client ID " <<  
     162                BOX_FORMAT_ACCOUNT(rContext.GetClientID())); 
    144163 
    145164        // Let the context know about it 
     
    312331                        if(en == 0) 
    313332                        { 
    314                                 ::syslog(LOG_ERR, "Object %llx in dir %llx for account %x references object %llx which does not exist in dir", 
    315                                         mObjectID, mInDirectory, rContext.GetClientID(), id); 
    316                                 return std::auto_ptr<ProtocolObject>(new BackupProtocolServerError( 
    317                                         BackupProtocolServerError::ErrorType, BackupProtocolServerError::Err_PatchConsistencyError));                    
     333                                BOX_ERROR("Object " <<  
     334                                        BOX_FORMAT_OBJECTID(mObjectID) << 
     335                                        " in dir " <<  
     336                                        BOX_FORMAT_OBJECTID(mInDirectory) << 
     337                                        " for account " << 
     338                                        BOX_FORMAT_ACCOUNT(rContext.GetClientID()) << 
     339                                        " references object " <<  
     340                                        BOX_FORMAT_OBJECTID(id) << 
     341                                        " which does not exist in dir"); 
     342                                return std::auto_ptr<ProtocolObject>( 
     343                                        new BackupProtocolServerError( 
     344                                                BackupProtocolServerError::ErrorType, 
     345                                                BackupProtocolServerError::Err_PatchConsistencyError));                  
    318346                        } 
    319347                        id = en->GetDependsNewer(); 
    320                 } while(en != 0 && id != 0); 
     348                } 
     349                while(en != 0 && id != 0); 
    321350                 
    322351                // OK! The last entry in the chain is the full file, the others are patches back from it. 
  • box/chris/general/bin/bbstored/BackupStoreDaemon.cpp

    r1691 r1784  
    209209                                ::openlog("bbstored/hk", LOG_PID, LOG_LOCAL6); 
    210210                                // Log that housekeeping started 
    211                                 ::syslog(LOG_INFO, "Housekeeping process started"); 
     211                                BOX_INFO("Housekeeping process started"); 
    212212                                // Ignore term and hup 
    213213                                // Parent will handle these and alert the child via the socket, don't want to randomly die 
     
    282282        catch(BoxException &e) 
    283283        { 
    284                 ::syslog(LOG_ERR, "%s: disconnecting due to " 
    285                         "exception %s (%d/%d)", DaemonName(),  
    286                         e.what(), e.GetType(), e.GetSubType()); 
     284    &n