comparison OrthancServer/Sources/main.cpp @ 4273:0034f855c023

tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Nov 2020 12:24:50 +0100
parents 251a8b07fa37
children 58e757ded69e
comparison
equal deleted inserted replaced
4272:1661544ea94d 4273:0034f855c023
639 << "\t\t\tdatabase (beware that the database will become" << std::endl 639 << "\t\t\tdatabase (beware that the database will become" << std::endl
640 << "\t\t\tincompatible with former versions of Orthanc)" << std::endl 640 << "\t\t\tincompatible with former versions of Orthanc)" << std::endl
641 << " --no-jobs\t\tDon't restart the jobs that were stored during" << std::endl 641 << " --no-jobs\t\tDon't restart the jobs that were stored during" << std::endl
642 << "\t\t\tthe last execution of Orthanc" << std::endl 642 << "\t\t\tthe last execution of Orthanc" << std::endl
643 << " --version\t\toutput version information and exit" << std::endl 643 << " --version\t\toutput version information and exit" << std::endl
644 << std::endl
645 << "Fine-tuning of log categories:" << std::endl;
646
647 for (size_t i = 0; i < Logging::GetCategoriesCount(); i++)
648 {
649 const std::string name = Logging::GetCategoryName(i);
650 std::cout << " --verbose-" << name
651 << "\tbe verbose in logs of category \"" << name << "\"" << std::endl;
652 std::cout << " --trace-" << name
653 << "\tuse highest verbosity for logs of category \"" << name << "\"" << std::endl;
654 }
655
656 std::cout
644 << std::endl 657 << std::endl
645 << "Exit status:" << std::endl 658 << "Exit status:" << std::endl
646 << " 0 if success," << std::endl 659 << " 0 if success," << std::endl
647 #if defined(_WIN32) 660 #if defined(_WIN32)
648 << "!= 0 if error (use the --errors option to get the list of possible errors)." << std::endl 661 << "!= 0 if error (use the --errors option to get the list of possible errors)." << std::endl
1493 { 1506 {
1494 return ConfigurePlugins(argc, argv, upgradeDatabase, loadJobsFromDatabase); 1507 return ConfigurePlugins(argc, argv, upgradeDatabase, loadJobsFromDatabase);
1495 } 1508 }
1496 1509
1497 1510
1498 static void SetLoggingCategories(Logging::LogLevel level, 1511 static bool SetCategoryVerbosity(const Verbosity verbosity,
1499 const std::string& lst) 1512 const std::string& category)
1500 { 1513 {
1501 std::vector<std::string> categories; 1514 Logging::LogCategory c;
1502 Toolbox::TokenizeString(categories, lst, ':'); 1515 if (LookupCategory(c, category))
1503 for (size_t i = 0; i < categories.size(); i++) 1516 {
1504 { 1517 SetCategoryVerbosity(c, verbosity);
1505 Logging::SetCategoryEnabled(level, Logging::StringToCategory(categories[i]), true); 1518 return true;
1519 }
1520 else
1521 {
1522 return false;
1506 } 1523 }
1507 } 1524 }
1508 1525
1509 1526
1510 static bool DisplayPerformanceWarning() 1527 static bool DisplayPerformanceWarning()
1567 PrintVersion(argv[0]); 1584 PrintVersion(argv[0]);
1568 return 0; 1585 return 0;
1569 } 1586 }
1570 else if (argument == "--verbose") 1587 else if (argument == "--verbose")
1571 { 1588 {
1572 Logging::EnableInfoLevel(true); 1589 SetGlobalVerbosity(Verbosity_Verbose);
1573 } 1590 }
1574 else if (argument == "--trace") 1591 else if (argument == "--trace")
1575 { 1592 {
1576 Logging::EnableTraceLevel(true); 1593 SetGlobalVerbosity(Verbosity_Trace);
1577 } 1594 }
1578 else if (boost::starts_with(argument, "--verbose=")) // New in Orthanc 1.8.1 1595 else if (boost::starts_with(argument, "--verbose-") &&
1579 { 1596 SetCategoryVerbosity(Verbosity_Verbose, argument.substr(10)))
1580 SetLoggingCategories(Logging::LogLevel_INFO, argument.substr(10)); 1597 {
1581 } 1598 // New in Orthanc 1.8.1
1582 else if (boost::starts_with(argument, "--trace=")) // New in Orthanc 1.8.1 1599 }
1583 { 1600 else if (boost::starts_with(argument, "--trace-") &&
1584 SetLoggingCategories(Logging::LogLevel_TRACE, argument.substr(8)); 1601 SetCategoryVerbosity(Verbosity_Trace, argument.substr(8)))
1602 {
1603 // New in Orthanc 1.8.1
1585 } 1604 }
1586 else if (boost::starts_with(argument, "--logdir=")) 1605 else if (boost::starts_with(argument, "--logdir="))
1587 { 1606 {
1588 // TODO WHAT IS THE ENCODING? 1607 // TODO WHAT IS THE ENCODING?
1589 const std::string directory = argument.substr(9); 1608 const std::string directory = argument.substr(9);