Changeset 1790

Show
Ignore:
Timestamp:
03/08/2007 00:29:31 (17 months ago)
Author:
chris
Message:

Convert most printf() and fprintf() calls to use logging framework
instead. (merges [1789])

Location:
box/chris/general
Files:
14 modified

Legend:

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

    r1784 r1790  
    110110 
    111111        // Read in the configuration file 
    112         if(!quiet) printf("Using configuration file %s\n",  
    113                 configFilename.c_str()); 
     112        if(!quiet) BOX_NOTICE("Using configuration file " << configFilename); 
    114113 
    115114        std::string errs; 
     
    120119        if(config.get() == 0 || !errs.empty()) 
    121120        { 
    122                 printf("Invalid configuration file:\n%s", errs.c_str()); 
     121                BOX_ERROR("Invalid configuration file: " << errs); 
    123122                return 1; 
    124123        } 
     
    129128        if(!conf.KeyExists("CommandSocket")) 
    130129        { 
    131                 printf("Daemon isn't using a control socket, " 
     130                BOX_ERROR("Daemon isn't using a control socket, " 
    132131                        "could not execute command.\n" 
    133132                        "Add a CommandSocket declaration to the " 
    134                         "bbackupd.conf file.\n"); 
     133                        "bbackupd.conf file."); 
    135134                return 1; 
    136135        } 
     
    154153        catch(...) 
    155154        { 
    156                 printf("Failed to connect to daemon control socket.\n" 
     155                BOX_ERROR("Failed to connect to daemon control socket.\n" 
    157156                        "Possible causes:\n" 
    158157                        "  * Daemon not running\n" 
    159158                        "  * Daemon busy syncing with store server\n" 
    160159                        "  * Another bbackupctl process is communicating with the daemon\n" 
    161                         "  * Daemon is waiting to recover from an error\n" 
     160                        "  * Daemon is waiting to recover from an error" 
    162161                ); 
    163  
    164 #if defined WIN32 && ! defined NDEBUG 
    165                 BOX_ERROR("Failed to connect to the command socket"); 
    166 #endif 
    167162 
    168163                return 1; 
     
    194189                        &updateStoreInterval, &minimumFileAge, &maxUploadWait) != 4) 
    195190        { 
    196                 printf("Config summary didn't decode\n"); 
     191                BOX_ERROR("Config summary didn't decode."); 
    197192                return 1; 
    198193        } 
     
    200195        if(!quiet) 
    201196        { 
    202                 printf("Daemon configuration summary:\n" 
    203                         "  AutomaticBackup = %s\n" 
    204                         "  UpdateStoreInterval = %d seconds\n" 
    205                         "  MinimumFileAge = %d seconds\n" 
    206                         "  MaxUploadWait = %d seconds\n", 
    207                         autoBackup?"true":"false", updateStoreInterval,  
    208                         minimumFileAge, maxUploadWait); 
     197                BOX_INFO("Daemon configuration summary:\n" 
     198                        "  AutomaticBackup = " <<  
     199                        (autoBackup?"true":"false") << "\n" 
     200                        "  UpdateStoreInterval = " << updateStoreInterval <<  
     201                        " seconds\n" 
     202                        "  MinimumFileAge = " << minimumFileAge << " seconds\n" 
     203                        "  MaxUploadWait = " << maxUploadWait << " seconds\n"); 
    209204        } 
    210205 
     
    267262                        if (currentState != 0) 
    268263                        { 
    269                                 printf("Waiting for current sync/error state " 
    270                                         "to finish...\n"); 
     264                                BOX_INFO("Waiting for current sync/error state " 
     265                                        "to finish..."); 
    271266                        } 
    272267                } 
     
    311306                                if(line == "start-sync") 
    312307                                { 
    313                                         if (!quiet) printf("Sync started...\n"); 
     308                                        if (!quiet) BOX_INFO("Sync started..."); 
    314309                                        syncIsRunning = true; 
    315310                                } 
     
    318313                                        if (syncIsRunning) 
    319314                                        { 
    320                                                 if (!quiet) printf("Sync finished.\n"); 
     315                                                if (!quiet) BOX_INFO("Sync finished.\n"); 
    321316                                                // Send a quit command to finish nicely 
    322317                                                connection.Write("quit\n", 5); 
     
    327322                                        else 
    328323                                        { 
    329                                                 if (!quiet) printf("Previous sync finished.\n"); 
     324                                                if (!quiet) BOX_INFO("Previous sync finished."); 
    330325                                        } 
    331326                                        // daemon must still be busy 
     
    341336                                        if(!quiet) 
    342337                                        { 
    343                                                 printf("Succeeded.\n"); 
     338                                                BOX_INFO("Succeeded.\n"); 
    344339                                        } 
    345340                                        finished = true; 
     
    347342                                else if(line == "error") 
    348343                                { 
    349                                         printf("ERROR. (Check command spelling)\n"); 
     344                                        BOX_ERROR("Check command spelling"); 
    350345                                        returnCode = 1; 
    351346                                        finished = true; 
  • box/chris/general/bin/bbackupquery/BackupQueries.cpp

    r1784 r1790  
    182182                                GetConsoleCP())) 
    183183                        { 
    184                                 printf("Failed to convert encoding"); 
     184                                BOX_ERROR("Failed to convert encoding"); 
    185185                                return; 
    186186                        } 
     
    256256                if(alias[a] == 0) 
    257257                { 
    258                         printf("Unrecognised command: %s\n", Command); 
     258                        BOX_ERROR("Unrecognised command: " << Command); 
    259259                        return; 
    260260                } 
     
    276276                        if(::strchr(commands[cmd].opts, *c) == NULL) 
    277277                        { 
    278                                 printf("Invalid option '%c' for command %s\n",  
    279                                         *c, commands[cmd].name); 
     278                                BOX_ERROR("Invalid option '" << *c << "' for " 
     279                                        "command " << commands[cmd].name); 
    280280                                return; 
    281281                        } 
     
    306306                { 
    307307                        // Simple implementation, so do it here 
    308                         printf("%s (%08llx)\n",  
    309                                 GetCurrentDirectoryName().c_str(),  
    310                                 (long long)GetCurrentDirectoryID()); 
     308                        BOX_INFO(GetCurrentDirectoryName() << " (" << 
     309                                BOX_FORMAT_OBJECTID(GetCurrentDirectoryID())); 
    311310                } 
    312311                break; 
     
    321320                 
    322321        case COMMAND_sh: 
    323                 printf("The command to run must be specified as an argument.\n"); 
     322                BOX_ERROR("The command to run must be specified as an argument."); 
    324323                break; 
    325324                 
     
    402401                if(rootDir == 0) 
    403402                { 
    404                         printf("Directory '%s' not found on store\n", 
    405                                 args[0].c_str()); 
     403                        BOX_ERROR("Directory '" << args[0] << "' not found " 
     404                                "on store."); 
    406405                        return; 
    407406                } 
     
    748747        if(args.size() != 1 || args[0].size() == 0) 
    749748        { 
    750                 printf("Incorrect usage.\ncd [-o] [-d] <directory>\n"); 
     749                BOX_ERROR("Incorrect usage. cd [-o] [-d] <directory>"); 
    751750                return; 
    752751        } 
     
    765764        if(id == 0) 
    766765        { 
    767                 printf("Directory '%s' not found\n", args[0].c_str()); 
     766                BOX_ERROR("Directory '" << args[0] << "' not found."); 
    768767                return; 
    769768        } 
     
    786785        if(args.size() != 1 || args[0].size() == 0) 
    787786        { 
    788                 printf("Incorrect usage.\nlcd <local-directory>\n"); 
     787                BOX_ERROR("Incorrect usage. lcd <local-directory>"); 
    789788                SetReturnCode(COMMAND_RETURN_ERROR); 
    790789                return; 
     
    796795        if(!ConvertConsoleToUtf8(args[0].c_str(), dirName)) 
    797796        { 
    798                 printf("Failed to convert path from console encoding.\n"); 
     797                BOX_ERROR("Failed to convert path from console encoding."); 
    799798                SetReturnCode(COMMAND_RETURN_ERROR); 
    800799                return; 
     
    806805        if(result != 0) 
    807806        { 
    808                 printf((errno == ENOENT || errno == ENOTDIR)?"Directory '%s' does not exist\n":"Error changing dir to '%s'\n", 
    809                         args[0].c_str()); 
     807                if(errno == ENOENT || errno == ENOTDIR) 
     808                { 
     809                        BOX_ERROR("Directory '" << args[0] << "' does not exist."); 
     810                } 
     811                else 
     812                { 
     813                        BOX_ERROR("Error changing to directory '" << 
     814                                args[0] << ": " << strerror(errno)); 
     815                } 
     816 
    810817                SetReturnCode(COMMAND_RETURN_ERROR); 
    811818                return; 
     
    816823        if(::getcwd(wd, PATH_MAX) == 0) 
    817824        { 
    818                 printf("Error getting current directory\n"); 
     825                BOX_ERROR("Error getting current directory: " << 
     826                        strerror(errno)); 
    819827                SetReturnCode(COMMAND_RETURN_ERROR); 
    820828                return; 
     
    824832        if(!ConvertUtf8ToConsole(wd, dirName)) 
    825833        { 
    826                 printf("Failed to convert new path from console encoding.\n"); 
     834                BOX_ERROR("Failed to convert new path from console encoding."); 
    827835                SetReturnCode(COMMAND_RETURN_ERROR); 
    828836                return; 
    829837        } 
    830         printf("Local current directory is now '%s'\n", dirName.c_str()); 
     838        BOX_INFO("Local current directory is now '" << dirName << "'."); 
    831839#else 
    832         printf("Local current directory is now '%s'\n", wd); 
     840        BOX_INFO("Local current directory is now '" << wd << "'."); 
    833841#endif 
    834842} 
     
    848856        if(args.size() != 2) 
    849857        { 
    850                 printf("Incorrect usage.\ngetobject <object-id> <local-filename>\n"); 
     858                BOX_ERROR("Incorrect usage. getobject <object-id> " 
     859                        "<local-filename>"); 
    851860                return; 
    852861        } 
     
    855864        if(id == std::numeric_limits<long long>::min() || id == std::numeric_limits<long long>::max() || id == 0) 
    856865        { 
    857                 printf("Not a valid object ID (specified in hex)\n"); 
     866                BOX_ERROR("Not a valid object ID (specified in hex)."); 
    858867                return; 
    859868        } 
     
    863872        if(::stat(args[1].c_str(), &st) == 0 || errno != ENOENT) 
    864873        { 
    865                 printf("The local file %s already exists\n", args[1].c_str()); 
     874                BOX_ERROR("The local file '" << args[1] << " already exists."); 
    866875                return; 
    867876        } 
     
    881890                        objectStream->CopyStreamTo(out); 
    882891                         
    883                         printf("Object ID %08llx fetched successfully.\n", id); 
     892                        BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(id) << 
     893                                " fetched successfully."); 
    884894                } 
    885895                else 
    886896                { 
    887                         printf("Object does not exist on store.\n"); 
     897                        BOX_ERROR("Object ID " << BOX_FORMAT_OBJECTID(id) << 
     898                                " does not exist on store."); 
    888899                        ::unlink(args[1].c_str()); 
    889900                } 
     
    892903        { 
    893904                ::unlink(args[1].c_str()); 
    894                 printf("Error occured fetching object.\n"); 
     905                BOX_ERROR("Error occured fetching object."); 
    895906        } 
    896907} 
     
    912923        if(args.size() < 1 || (opts['i'] && args.size() != 2) || args.size() > 2) 
    913924        { 
    914                 printf("Incorrect usage.\n" 
     925                BOX_ERROR("Incorrect usage.\n" 
    915926                        "get <remote-filename> [<local-filename>] or\n" 
    916                         "get -i <object-id> <local-filename>\n"); 
     927                        "get -i <object-id> <local-filename>"); 
    917928                return; 
    918929        } 
     
    932943                        if(!ConvertConsoleToUtf8(i->c_str(), out)) 
    933944                        { 
    934                                 fprintf(stderr, "failed to convert encoding\n"); 
     945                                BOX_ERROR("Failed to convert encoding."); 
    935946                                return; 
    936947                        } 
     
    953964                                if(dirId == 0) 
    954965                                { 
    955                                         printf("Directory '%s' not found\n",  
    956                                                 dirName.c_str()); 
     966                                        BOX_ERROR("Directory '" << dirName << 
     967                                                "' not found."); 
    957968                                        return; 
    958969                                } 
     
    982993                                fileId == 0) 
    983994                        { 
    984                                 printf("Not a valid object ID (specified in hex)\n"); 
     995                                BOX_ERROR("Not a valid object ID (specified in hex)."); 
    985996                                return; 
    986997                        } 
     
    9891000                        if(dir.FindEntryByID(fileId) == 0) 
    9901001                        { 
    991                                 printf("ID '%08llx' not found in current " 
     1002                                BOX_ERROR("File ID " <<  
     1003                                        BOX_FORMAT_OBJECTID(fileId) << 
     1004                                        " not found in current " 
    9921005                                        "directory on store.\n" 
    993                                         "(You can only download objects by ID " 
    994                                         "from the current directory.)\n",  
    995                                         fileId); 
     1006                                        "(You can only download files by ID " 
     1007                                        "from the current directory.)"); 
    9961008                                return; 
    9971009                        } 
     
    10081020                        if(en == 0) 
    10091021                        { 
    1010                                 printf("Filename '%s' not found in current " 
     1022                                BOX_ERROR("Filename '" << args[0] << "' " 
     1023                                        "not found in current " 
    10111024                                        "directory on store.\n" 
    10121025                                        "(Subdirectories in path not " 
    1013                                         "searched.)\n", args[0].c_str()); 
     1026                                        "searched.)"); 
    10141027                                return; 
    10151028                        } 
     
    10281041        if(::stat(localName.c_str(), &st) == 0 || errno != ENOENT) 
    10291042        { 
    1030                 printf("The local file %s already exists, will not " 
    1031                         "overwrite it.\n", localName.c_str()); 
     1043                BOX_ERROR("The local file " << localName << " already exists, " 
     1044                        "will not overwrite it."); 
    10321045                SetReturnCode(COMMAND_RETURN_ERROR); 
    10331046                return; 
     
    10471060 
    10481061                // Done. 
    1049                 printf("Object ID %08llx fetched sucessfully.\n", fileId); 
     1062                BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(fileId) << 
     1063                        " fetched successfully."); 
    10501064        } 
    10511065        catch (BoxException &e) 
     
    11611175                else 
    11621176                { 
    1163                         printf("Warning: couldn't determine the time of the last synchronisation -- checks not performed.\n"); 
     1177                        BOX_WARNING("Failed to determine the time of the last " 
     1178                                "synchronisation -- checks not performed."); 
    11641179                } 
    11651180        } 
     
    11681183        if(params.mQuickCompare) 
    11691184        { 
    1170                 printf("WARNING: Quick compare used -- file attributes are not checked.\n"); 
     1185                BOX_WARNING("Quick compare used -- file attributes are not " 
     1186                        "checked."); 
    11711187        } 
    11721188         
     
    11931209                if(!params.mIgnoreExcludes) 
    11941210                { 
    1195                         printf("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes\n"); 
     1211                        BOX_ERROR("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes."); 
    11961212                        return; 
    11971213                } 
     
    12041220        else 
    12051221        { 
    1206                 printf("Incorrect usage.\ncompare -a\n or compare -l <location-name>\n or compare <store-dir-name> <local-dir-name>\n"); 
     1222                BOX_ERROR("Incorrect usage.\ncompare -a\n or compare -l <location-name>\n or compare <store-dir-name> <local-dir-name>"); 
    12071223                return; 
    12081224        } 
     
    12101226        if (!params.mQuietCompare) 
    12111227        {        
    1212                 printf("\n[ %d (of %d) differences probably due to file " 
    1213                         "modifications after the last upload ]\n", 
    1214                         params.mDifferencesExplainedByModTime,  
    1215                         params.mDifferences); 
    1216         } 
    1217  
    1218         printf("Differences: %d (%d dirs excluded, %d files excluded, " 
    1219                 "%d files not checked)\n", 
    1220                 params.mDifferences, params.mExcludedDirs,  
    1221                 params.mExcludedFiles, params.mUncheckedFiles); 
     1228                BOX_INFO("[ " << 
     1229                        params.mDifferencesExplainedByModTime << " (of " << 
     1230                        params.mDifferences << ") differences probably " 
     1231                        "due to file modifications after the last upload ]"); 
     1232        } 
     1233 
     1234        BOX_INFO("Differences: " << params.mDifferences << " (" << 
     1235                params.mExcludedDirs   << " dirs excluded, " << 
     1236                params.mExcludedFiles  << " files excluded, " << 
     1237                params.mUncheckedFiles << " files not checked)"); 
    12221238         
    12231239        // Set return code? 
     
    12541270        if(!locations.SubConfigurationExists(rLocation.c_str())) 
    12551271        { 
    1256                 printf("Location %s does not exist.\n", rLocation.c_str()); 
     1272                BOX_ERROR("Location " << rLocation << " does not exist."); 
    12571273                return; 
    12581274        } 
     
    12651281                        DIRECTORY_SEPARATOR_ASCHAR) 
    12661282                { 
    1267                         fprintf(stderr, "Warning: location '%s' path ends " 
    1268                                 "with '%s', compare may fail!", 
    1269                                 rLocation.c_str(), DIRECTORY_SEPARATOR); 
     1283                        BOX_WARNING("Location '" << rLocation << "' path ends " 
     1284                                "with '" DIRECTORY_SEPARATOR "', " 
     1285                                "compare may fail!"); 
    12701286                } 
    12711287        } 
     
    13201336        if(dirID == 0) 
    13211337        { 
    1322                 printf("Local directory '%s' exists, but " 
    1323                         "server directory '%s' does not exist\n",  
    1324                         rLocalDir.c_str(), rStoreDir.c_str());           
     1338                BOX_WARNING("Local directory '" << rLocalDir << "' exists, " 
     1339                        "but server directory '" << rStoreDir << "' does not " 
     1340                        "exist."); 
    13251341                rParams.mDifferences ++; 
    13261342                return; 
     
    13701386                if(errno == ENOTDIR) 
    13711387                { 
    1372                         printf("Local object '%s' is a file, " 
    1373                                 "server object '%s' is a directory\n",  
    1374                                 localDirDisplay.c_str(),  
    1375