[Box Backup-commit] COMMIT r2806 - box/trunk/lib/server

subversion at boxbackup.org subversion at boxbackup.org
Wed Nov 17 10:28:36 GMT 2010


Author: chris
Date: 2010-11-17 10:28:35 +0000 (Wed, 17 Nov 2010)
New Revision: 2806

Modified:
   box/trunk/lib/server/Daemon.cpp
   box/trunk/lib/server/Daemon.h
Log:
Add log file logging to all daemons.


Modified: box/trunk/lib/server/Daemon.cpp
===================================================================
--- box/trunk/lib/server/Daemon.cpp	2010-11-17 10:28:19 UTC (rev 2805)
+++ box/trunk/lib/server/Daemon.cpp	2010-11-17 10:28:35 UTC (rev 2806)
@@ -121,18 +121,19 @@
 	"  -F         Do not fork into background, but fork to serve multiple clients\n"
 #endif
 	"  -k         Keep console open after fork, keep writing log messages to it\n"
-#ifndef WIN32
 	"  -K         Stop writing log messages to console while daemon is running\n"
+	"  -o <file>  Log to a file, defaults to maximum verbosity\n"
+	"  -O <level> Set file log verbosity to error/warning/notice/info/trace/everything\n"
 	"  -P         Show process ID (PID) in console output\n"
-#endif
 	"  -q         Run more quietly, reduce verbosity level by one, can repeat\n"
-	"  -Q         Run at minimum verbosity, log nothing\n"
+	"  -Q         Run at minimum verbosity, log nothing to console and system\n"
+	"  -t <tag>   Tag console output with specified marker\n"
+	"  -T         Timestamp console output\n"
+	"  -U         Timestamp console output with microseconds\n"
 	"  -v         Run more verbosely, increase verbosity level by one, can repeat\n"
-	"  -V         Run at maximum verbosity, log everything\n"
+	"  -V         Run at maximum verbosity, log everything to console and sysystem\n"
 	"  -W <level> Set verbosity to error/warning/notice/info/trace/everything\n"
-	"  -t <tag>   Tag console output with specified marker\n"
-	"  -T         Timestamp console output\n"
-	"  -U         Timestamp console output with microseconds\n";
+	;
 }
 
 // --------------------------------------------------------------------------
@@ -171,6 +172,13 @@
 		break;
 #endif // !WIN32
 
+		case 'h':
+		{
+			Usage();
+			return 2;
+		}
+		break;
+
 		case 'k':
 		{
 			mKeepConsoleOpenAfterFork = true;
@@ -183,13 +191,24 @@
 		}
 		break;
 
-		case 'h':
+		case 'o':
 		{
-			Usage();
-			return 2;
+			mLogFile = optarg;
+			mLogFileLevel = Log::EVERYTHING;
 		}
 		break;
 
+		case 'O':
+		{
+			mLogFileLevel = Logging::GetNamedLevel(optarg);
+			if (mLogFileLevel == Log::INVALID)
+			{
+				BOX_FATAL("Invalid logging level: " << optarg);
+				return 2;
+			}
+		}
+		break;
+
 		case 'P':
 		{
 			Console::SetShowPID(true);
@@ -215,7 +234,26 @@
 		}
 		break;
 
+		case 't':
+		{
+			Logging::SetProgramName(optarg);
+			Console::SetShowTag(true);
+		}
+		break;
 
+		case 'T':
+		{
+			Console::SetShowTime(true);
+		}
+		break;
+
+		case 'U':
+		{
+			Console::SetShowTime(true);
+			Console::SetShowTimeMicros(true);
+		}
+		break;
+
 		case 'v':
 		{
 			if(mLogLevel == Log::EVERYTHING)
@@ -246,26 +284,6 @@
 		}
 		break;
 
-		case 't':
-		{
-			Logging::SetProgramName(optarg);
-			Console::SetShowTag(true);
-		}
-		break;
-
-		case 'T':
-		{
-			Console::SetShowTime(true);
-		}
-		break;
-
-		case 'U':
-		{
-			Console::SetShowTime(true);
-			Console::SetShowTimeMicros(true);
-		}
-		break;
-
 		case '?':
 		{
 			BOX_FATAL("Unknown option on command line: " 
@@ -360,6 +378,12 @@
 	Logging::FilterConsole((Log::Level)mLogLevel);
 	Logging::FilterSyslog ((Log::Level)mLogLevel);
 
+	if (mLogFileLevel != Log::INVALID)
+	{
+		mapLogFileLogger.reset(
+			new FileLogger(mLogFile, mLogFileLevel));
+	}
+
 	return Main(mConfigFileName);
 }
 

Modified: box/trunk/lib/server/Daemon.h
===================================================================
--- box/trunk/lib/server/Daemon.h	2010-11-17 10:28:19 UTC (rev 2805)
+++ box/trunk/lib/server/Daemon.h	2010-11-17 10:28:35 UTC (rev 2806)
@@ -99,6 +99,9 @@
 	bool mKeepConsoleOpenAfterFork;
 	bool mHaveConfigFile;
 	int mLogLevel; // need an int to do math with
+	std::string mLogFile;
+	Log::Level mLogFileLevel;
+	std::auto_ptr<FileLogger> mapLogFileLogger;
 	static Daemon *spDaemon;
 	std::string mAppName;
 };




More information about the Boxbackup-commit mailing list