Ignore:
Timestamp:
03/08/2007 00:29:31 (5 years ago)
Author:
chris
Message:

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

File:
1 edited

Legend:

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

    r1690 r1790  
    3838        if(SoftLimit >= HardLimit) 
    3939        { 
    40                 printf("ERROR: Soft limit must be less than the hard limit.\n"); 
     40                BOX_FATAL("Soft limit must be less than the hard limit."); 
    4141                exit(1); 
    4242        } 
    4343        if(SoftLimit > ((HardLimit * MAX_SOFT_LIMIT_SIZE) / 100)) 
    4444        { 
    45                 printf("ERROR: Soft limit must be no more than %d%% of the hard limit.\n", MAX_SOFT_LIMIT_SIZE); 
     45                BOX_FATAL("Soft limit must be no more than " <<  
     46                        MAX_SOFT_LIMIT_SIZE << "% of the hard limit."); 
    4647                exit(1); 
    4748        } 
     
    5455        if(DiscSet < 0 || DiscSet >= controller.GetNumDiscSets()) 
    5556        { 
    56                 printf("Disc set %d does not exist\n", DiscSet); 
     57                BOX_FATAL("Disc set " << DiscSet << " does not exist."); 
    5758                exit(1); 
    5859        } 
     
    9091        if(endptr == string || number == LONG_MIN || number == LONG_MAX) 
    9192        { 
    92                 printf("%s is an invalid number\n", string); 
     93                BOX_FATAL("'" << string << "' is not a valid number."); 
    9394                exit(1); 
    9495        } 
     
    117118         
    118119        default: 
    119                 printf("%s has an invalid units specifier\nUse B for blocks, M for Mb, G for Gb, eg 2Gb\n", string); 
     120                BOX_FATAL(string << " has an invalid units specifier " 
     121                        "(use B for blocks, M for Mb, G for Gb, eg 2Gb)"); 
    120122                exit(1); 
    121123                break;           
     
    144146        { 
    145147                // Couldn't lock the account -- just stop now 
    146                 printf("Couldn't lock the account -- did not change the limits\nTry again later.\n"); 
     148                BOX_ERROR("Failed to lock the account, did not change limits. " 
     149                        "Try again later."); 
    147150                return 1; 
    148151        } 
     
    169172        if(!db->EntryExists(ID)) 
    170173        { 
    171                 printf("Account %x does not exist\n", ID); 
     174                BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<  
     175                        " does not exist."); 
    172176                return 1; 
    173177        } 
     
    199203        info->Save(); 
    200204 
    201         printf("Limits on account 0x%08x changed to %lld soft, %lld hard\n", ID, softlimit, hardlimit); 
     205        BOX_NOTICE("Limits on account " << BOX_FORMAT_ACCOUNT(ID) << 
     206                " changed to " << softlimit << " soft, " << 
     207                hardlimit << " hard."); 
    202208 
    203209        return 0; 
     
    212218        if(!db->EntryExists(ID)) 
    213219        { 
    214                 printf("Account %x does not exist\n", ID); 
     220                BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<  
     221                        " does not exist."); 
    215222                return 1; 
    216223        } 
     
    242249        if(AskForConfirmation) 
    243250        { 
    244                 ::printf("Really delete account %08x?\n(type 'yes' to confirm)\n", ID); 
     251                BOX_WARNING("Really delete account " <<  
     252                        BOX_FORMAT_ACCOUNT(ID) << "? (type 'yes' to confirm)"); 
    245253                char response[256]; 
    246254                if(::fgets(response, sizeof(response), stdin) == 0 || ::strcmp(response, "yes\n") != 0) 
    247255                { 
    248                         printf("Deletion cancelled\n"); 
     256                        BOX_NOTICE("Deletion cancelled."); 
    249257                        return 0; 
    250258                } 
     
    257265        if(!db->EntryExists(ID)) 
    258266        { 
    259                 printf("Account %x does not exist\n", ID); 
     267                BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<  
     268                        " does not exist."); 
    260269                return 1; 
    261270        } 
     
    319328                } 
    320329        } 
    321          
     330 
     331        int retcode = 0; 
     332 
    322333        // Thirdly, delete the directories... 
    323334        for(std::vector<std::string>::const_iterator d(toDelete.begin()); d != toDelete.end(); ++d) 
    324335        { 
    325                 ::printf("Deleting store directory %s...\n", (*d).c_str()); 
     336                BOX_NOTICE("Deleting store directory " << (*d) << "..."); 
    326337                // Just use the rm command to delete the files 
    327338                std::string cmd("rm -rf "); 
     
    330341                if(::system(cmd.c_str()) != 0) 
    331342                { 
    332                         ::printf("ERROR: Deletion of %s failed.\n(when cleaning up, remember to delete all raid directories)\n", (*d).c_str()); 
    333                         return 1; 
     343                        BOX_ERROR("Failed to delete files in " << (*d) << 
     344                                ", delete them manually."); 
     345                        retcode = 1; 
    334346                } 
    335347        } 
    336348         
    337349        // Success! 
    338         return 0; 
     350        return retcode; 
    339351} 
    340352 
     
    347359        if(!db->EntryExists(ID)) 
    348360        { 
    349                 printf("Account %x does not exist\n", ID); 
     361                BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<  
     362                        " does not exist."); 
    350363                return 1; 
    351364        } 
     
    382395        if(db->EntryExists(ID)) 
    383396        { 
    384                 printf("Account %x already exists\n", ID); 
     397                BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<  
     398                        " already exists."); 
    385399                return 1; 
    386400        } 
     
    390404        acc.Create(ID, DiscNumber, SoftLimit, HardLimit, rUsername); 
    391405         
    392         printf("Account %x created\n", ID); 
     406        BOX_NOTICE("Account " << BOX_FORMAT_ACCOUNT(ID) << " created."); 
    393407 
    394408        return 0; 
     
    445459        if(config.get() == 0 || !errs.empty()) 
    446460        { 
    447                 printf("Invalid configuration file:\n%s", errs.c_str()); 
     461                BOX_ERROR("Invalid configuration file " << configFilename << 
     462                        ":" << errs); 
    448463        } 
    449464         
     
    485500                        || ::sscanf(argv[2], "%d", &discnum) != 1) 
    486501                { 
    487                         printf("create requires raid file disc number, soft and hard limits\n"); 
     502                        BOX_ERROR("create requires raid file disc number, " 
     503                                "soft and hard limits."); 
    488504                        return 1; 
    489505                } 
     
    507523                if(argc < 4) 
    508524                { 
    509                         printf("setlimit requires soft and hard limits\n"); 
     525                        BOX_ERROR("setlimit requires soft and hard limits."); 
    510526                        return 1; 
    511527                } 
     
    541557                        else 
    542558                        { 
    543                                 ::printf("Unknown option %s.\n", argv[o]); 
     559                                BOX_ERROR("Unknown option " << argv[o] << "."); 
    544560                                return 2; 
    545561                        } 
     
    551567        else 
    552568        { 
    553                 printf("Unknown command '%s'\n", argv[0]); 
     569                BOX_ERROR("Unknown command '" << argv[0] << "'."); 
    554570                return 1; 
    555571        } 
Note: See TracChangeset for help on using the changeset viewer.