comparison OrthancServer/main.cpp @ 2015:bcc575732aef

New option "--logfile" to output the Orthanc log to the given file
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 13 Jun 2016 15:07:53 +0200
parents 4dafe2a0d3ab
children 300599489cab
comparison
equal deleted inserted replaced
2014:e39a2657f1c6 2015:bcc575732aef
441 << "instructions about how to use Orthanc <http://www.orthanc-server.com/>." << std::endl 441 << "instructions about how to use Orthanc <http://www.orthanc-server.com/>." << std::endl
442 << std::endl 442 << std::endl
443 << "Command-line options:" << std::endl 443 << "Command-line options:" << std::endl
444 << " --help\t\tdisplay this help and exit" << std::endl 444 << " --help\t\tdisplay this help and exit" << std::endl
445 << " --logdir=[dir]\tdirectory where to store the log files" << std::endl 445 << " --logdir=[dir]\tdirectory where to store the log files" << std::endl
446 << "\t\t\t(if not used, the logs are dumped to stderr)" << std::endl 446 << "\t\t\t(by default, the log is dumped to stderr)" << std::endl
447 << " --logfile=[file]\tfile where to store the log of Orthanc" << std::endl
448 << "\t\t\t(by default, the log is dumped to stderr)" << std::endl
447 << " --config=[file]\tcreate a sample configuration file and exit" << std::endl 449 << " --config=[file]\tcreate a sample configuration file and exit" << std::endl
448 << " --errors\t\tprint the supported error codes and exit" << std::endl 450 << " --errors\t\tprint the supported error codes and exit" << std::endl
449 << " --verbose\t\tbe verbose in logs" << std::endl 451 << " --verbose\t\tbe verbose in logs" << std::endl
450 << " --trace\t\thighest verbosity in logs (for debug)" << std::endl 452 << " --trace\t\thighest verbosity in logs (for debug)" << std::endl
451 << " --upgrade\t\tallow Orthanc to upgrade the version of the" << std::endl 453 << " --upgrade\t\tallow Orthanc to upgrade the version of the" << std::endl
659 restart = restApi.IsResetRequestReceived(); 661 restart = restApi.IsResetRequestReceived();
660 662
661 if (!restart && 663 if (!restart &&
662 event == ServerBarrierEvent_Reload) 664 event == ServerBarrierEvent_Reload)
663 { 665 {
666 // Handling of SIGHUP
667
664 if (Configuration::HasConfigurationChanged()) 668 if (Configuration::HasConfigurationChanged())
665 { 669 {
666 LOG(WARNING) << "A SIGHUP signal has been received, resetting Orthanc"; 670 LOG(WARNING) << "A SIGHUP signal has been received, resetting Orthanc";
671 Logging::Flush();
667 restart = true; 672 restart = true;
668 break; 673 break;
669 } 674 }
670 else 675 else
671 { 676 {
672 LOG(WARNING) << "A SIGHUP signal has been received, but is ignored as the configuration has not changed"; 677 LOG(WARNING) << "A SIGHUP signal has been received, but is ignored as the configuration has not changed";
678 Logging::Flush();
673 continue; 679 continue;
674 } 680 }
675 } 681 }
676 else 682 else
677 { 683 {
1146 LOG(ERROR) << "The directory where to store the log files (" 1152 LOG(ERROR) << "The directory where to store the log files ("
1147 << directory << ") is inexistent, aborting."; 1153 << directory << ") is inexistent, aborting.";
1148 return -1; 1154 return -1;
1149 } 1155 }
1150 } 1156 }
1157 else if (boost::starts_with(argument, "--logfile="))
1158 {
1159 std::string file = argument.substr(10);
1160
1161 try
1162 {
1163 Logging::SetTargetFile(file);
1164 }
1165 catch (OrthancException&)
1166 {
1167 LOG(ERROR) << "Cannot write to the specified log file ("
1168 << file << "), aborting.";
1169 return -1;
1170 }
1171 }
1151 else if (argument == "--upgrade") 1172 else if (argument == "--upgrade")
1152 { 1173 {
1153 allowDatabaseUpgrade = true; 1174 allowDatabaseUpgrade = true;
1154 } 1175 }
1155 else if (boost::starts_with(argument, "--config=")) 1176 else if (boost::starts_with(argument, "--config="))
1206 1227
1207 bool restart = StartOrthanc(argc, argv, allowDatabaseUpgrade); 1228 bool restart = StartOrthanc(argc, argv, allowDatabaseUpgrade);
1208 if (restart) 1229 if (restart)
1209 { 1230 {
1210 OrthancFinalize(); 1231 OrthancFinalize();
1232 LOG(WARNING) << "Logging system is resetting";
1233 Logging::Reset();
1211 } 1234 }
1212 else 1235 else
1213 { 1236 {
1214 break; 1237 break;
1215 } 1238 }