1
0
Fork 0

Add “—-log-file” option, to log to other locations.

Each argument creates another log file, in the directory named. Symbolic
value ‘desktop’ creates logs on the user’s desktop.

Needs corresponding SimGear commit to build
This commit is contained in:
James Turner 2017-01-29 16:18:10 +01:00
parent 658074f78e
commit 5d27d2509f
2 changed files with 54 additions and 4 deletions

View file

@ -364,6 +364,8 @@ static void fgIdleFunction ( void ) {
}
if ( idle_state == 1000 ) {
sglog().setStartupLoggingEnabled(false);
// We've finished all our initialization steps, from now on we
// run the main loop.
fgSetBool("sim/sceneryloaded", false);
@ -410,7 +412,7 @@ extern "C" {
}
#endif
static void logToFile()
static void logToHome()
{
SGPath logPath = globals->get_fg_home();
logPath.append("fgfs.log");
@ -437,8 +439,10 @@ static void logToFile()
// Main top level initialization
int fgMainInit( int argc, char **argv )
{
// set default log levels
sglog().setLogLevels( SG_ALL, SG_ALERT );
// set default log level to 'info' for startup, we will revert to a lower
// level once startup is done.
sglog().setLogLevels( SG_ALL, SG_INFO );
sglog().setStartupLoggingEnabled(true);
globals = new FGGlobals;
if (!fgInitHome()) {
@ -447,7 +451,7 @@ int fgMainInit( int argc, char **argv )
if (!fgGetBool("/sim/fghome-readonly")) {
// now home is initialised, we can log to a file inside it
logToFile();
logToHome();
}
std::string version(FLIGHTGEAR_VERSION);

View file

@ -48,6 +48,7 @@
#include <simgear/props/props_io.hxx>
#include <simgear/misc/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <simgear/scene/material/mat.hxx>
#include <simgear/sound/soundmgr.hxx>
#include <simgear/misc/strutils.hxx>
@ -1053,6 +1054,50 @@ fgOptLogClasses( const char *arg )
return FG_OPTIONS_OK;
}
static int
fgOptLogFile(const char* arg)
{
SGPath dirPath;
if (!strcmp(arg, "desktop")) {
dirPath = SGPath::desktop();
} else {
dirPath = SGPath::fromLocal8Bit(arg);
}
if (!dirPath.isDir()) {
SG_LOG(SG_GENERAL, SG_ALERT, "cannot find logging location " << dirPath);
return FG_OPTIONS_ERROR;
}
if (!dirPath.canWrite()) {
SG_LOG(SG_GENERAL, SG_ALERT, "cannot write to logging location " << dirPath);
return FG_OPTIONS_ERROR;
}
// generate the log file name
SGPath logFile;
{
char fileNameBuffer[100];
time_t now;
time(&now);
strftime(fileNameBuffer, 99, "FlightGear_%F", localtime(&now));
unsigned int logsTodayCount = 0;
while (true) {
std::ostringstream os;
os << fileNameBuffer << "_" << logsTodayCount++ << ".log";
logFile = dirPath / os.str();
if (!logFile.exists()) {
break;
}
}
}
sglog().logToFile(logFile, sglog().get_log_classes(), sglog().get_log_priority());
return FG_OPTIONS_OK;
}
static int
fgOptTraceWrite( const char *arg )
{
@ -1660,6 +1705,7 @@ struct OptionDesc {
{"trace-write", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptTraceWrite },
{"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
{"log-class", true, OPTION_FUNC, "", false, "", fgOptLogClasses },
{"log-file", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptLogFile },
{"view-offset", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptViewOffset },
{"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
{"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },