@@ -161,23 +161,32 @@ void SDL_Log_Output(void* /*userdata*/, int category, SDL_LogPriority priority,
161161// Log configuration
162162// ----------------------------------------------------------------------------
163163
164- PDebugOutput create_log_output (const String &name, const String &path = " " , LogFile::OpenMode open_mode = LogFile::kLogFile_Overwrite )
164+ // Create a new log output by ID
165+ PDebugOutput create_log_output (const String &name, const String &dir = " " , const String &filename = " " ,
166+ LogFile::OpenMode open_mode = LogFile::kLogFile_Overwrite )
165167{
166- // Else create new one, if we know this ID
167168 if (name.CompareNoCase (OutputSystemID) == 0 )
168169 {
169170 return DbgMgr.RegisterOutput (OutputSystemID, AGSPlatformDriver::GetDriver (), kDbgMsg_None );
170171 }
171172 else if (name.CompareNoCase (OutputFileID) == 0 )
172173 {
173174 DebugLogFile.reset (new LogFile ());
174- String logfile_path = path ;
175- if (logfile_path .IsEmpty ())
175+ String logfile_dir = dir ;
176+ if (dir .IsEmpty ())
176177 {
177178 FSLocation fs = platform->GetAppOutputDirectory ();
178179 CreateFSDirs (fs);
179- logfile_path = Path::ConcatPaths ( fs.FullDir , " ags.log " ) ;
180+ logfile_dir = fs.FullDir ;
180181 }
182+ else if (Path::IsRelativePath (dir) && platform->IsLocalDirRestricted ())
183+ {
184+ FSLocation fs = GetGameUserDataDir ();
185+ CreateFSDirs (fs);
186+ logfile_dir = fs.FullDir ;
187+ }
188+ String logfilename = filename.IsEmpty () ? " ags.log" : filename;
189+ String logfile_path = Path::ConcatPaths (logfile_dir, logfilename);
181190 if (!DebugLogFile->OpenFile (logfile_path, open_mode))
182191 return nullptr ;
183192 Debug::Printf (kDbgMsg_Info , " Logging to %s" , logfile_path.GetCStr ());
@@ -336,7 +345,7 @@ void apply_debug_config(const ConfigTree &cfg)
336345 // then open "warnings.log" for printing script warnings.
337346 if (game.options [OPT_DEBUGMODE] != 0 && !DebugLogFile)
338347 {
339- auto dbgout = create_log_output (OutputFileID, " warnings.log" , LogFile::kLogFile_OverwriteAtFirstMessage );
348+ auto dbgout = create_log_output (OutputFileID, " ./ " , " warnings.log" , LogFile::kLogFile_OverwriteAtFirstMessage );
340349 if (dbgout)
341350 {
342351 dbgout->SetGroupFilter (kDbgGroup_Game , kDbgMsg_Warn );
0 commit comments