@@ -259,6 +259,13 @@ class logger
259
259
return false ;
260
260
}
261
261
262
+ // Re-open log file.
263
+ fs::path plogfile = pathDataDir / " scraper.log" ;
264
+ logfile.open (plogfile.c_str (), std::ios_base::out | std::ios_base::app);
265
+
266
+ if (!logfile.is_open ())
267
+ LogPrintf (" ERROR: Scraper: Logger: Failed to open logging file\n " );
268
+
262
269
PrevArchiveCheckDate = ArchiveCheckDate;
263
270
}
264
271
@@ -328,10 +335,20 @@ class logger
328
335
return true ;
329
336
}
330
337
else
338
+ {
331
339
return false ;
340
+ }
332
341
}
333
342
};
334
343
344
+ logger& LogInstance ()
345
+ {
346
+ // This is similar to Bitcoin's newer approach.
347
+ static logger* scraperlogger{new logger ()};
348
+ return *scraperlogger;
349
+ }
350
+
351
+
335
352
boost::gregorian::date logger::PrevArchiveCheckDate = boost::posix_time::from_time_t (GetAdjustedTime()).date();
336
353
CCriticalSection logger::cs_log;
337
354
@@ -361,11 +378,13 @@ void _log(logattribute eType, const std::string& sCall, const std::string& sMess
361
378
}
362
379
363
380
sOut = tfm::format (" %s [%s] <%s> : %s" , DateTimeStrFormat (" %x %H:%M:%S" , GetAdjustedTime ()), sType , sCall , sMessage );
364
- logger log;
381
+
382
+ // logger log;
383
+ logger& log = LogInstance ();
365
384
366
385
log.output (sOut );
367
386
368
- log.closelogfile ();
387
+ // log.closelogfile();
369
388
370
389
// Send to UI for log window.
371
390
uiInterface.NotifyScraperEvent (scrapereventtypes::Log, CT_NEW, sOut );
@@ -681,6 +700,7 @@ void ScraperApplyAppCacheEntries()
681
700
// It can also be called in "single shot" mode.
682
701
void Scraper (bool bSingleShot)
683
702
{
703
+
684
704
// Initialize these while still single-threaded. They cannot be initialized during declaration because GetDataDir()
685
705
// gives the wrong value that early. If they are already initialized then leave them alone (because this function
686
706
// can be called in singleshot mode.
@@ -693,6 +713,9 @@ void Scraper(bool bSingleShot)
693
713
pathScraper = pathDataDir / " Scraper" ;
694
714
}
695
715
716
+ // Initialize log singleton. Must be after the imbue.
717
+ LogInstance ();
718
+
696
719
if (!bSingleShot)
697
720
_log (logattribute::INFO, " Scraper" , " Starting Scraper thread." );
698
721
else
@@ -776,14 +799,14 @@ void Scraper(bool bSingleShot)
776
799
}
777
800
778
801
// Need the log archive check here, because we don't run housekeeping in this while loop.
779
- logger log;
802
+ logger& log = LogInstance () ;
780
803
781
804
fs::path plogfile_out;
782
805
783
806
if (log.archive (false , plogfile_out))
784
807
_log (logattribute::INFO, " Scraper" , " Archived scraper.log to " + plogfile_out.filename ().string ());
785
808
786
- log.closelogfile ();
809
+ // log.closelogfile();
787
810
788
811
sbage = SuperblockAge ();
789
812
_log (logattribute::INFO, " Scraper" , " Superblock not needed. age=" + std::to_string (sbage));
@@ -938,6 +961,9 @@ void NeuralNetwork()
938
961
pathDataDir.imbue (std::locale (std::locale (), new std::codecvt_utf8_utf16<wchar_t >()));
939
962
940
963
pathScraper = pathDataDir / " Scraper" ;
964
+
965
+ // Initialize log singleton. Must be after the imbue.
966
+ LogInstance ();
941
967
}
942
968
943
969
@@ -1040,14 +1066,14 @@ bool ScraperHousekeeping()
1040
1066
+ " , Popularity: " + std::to_string (network_hash.second ));
1041
1067
}
1042
1068
1043
- logger log;
1069
+ logger& log = LogInstance () ;
1044
1070
1045
1071
fs::path plogfile_out;
1046
1072
1047
1073
if (log.archive (false , plogfile_out))
1048
1074
_log (logattribute::INFO, " ScraperHousekeeping" , " Archived scraper.log to " + plogfile_out.filename ().string ());
1049
1075
1050
- log.closelogfile ();
1076
+ // log.closelogfile();
1051
1077
1052
1078
return true ;
1053
1079
}
@@ -4245,12 +4271,12 @@ UniValue archivescraperlog(const UniValue& params, bool fHelp)
4245
4271
" archivescraperlog takes no arguments and results in immediate archiving of the scraper log\n "
4246
4272
);
4247
4273
4248
- logger log;
4274
+ logger& log = LogInstance () ;
4249
4275
4250
4276
fs::path pfile_out;
4251
4277
bool ret = log.archive (true , pfile_out);
4252
4278
4253
- log.closelogfile ();
4279
+ // log.closelogfile();
4254
4280
4255
4281
return UniValue (ret);
4256
4282
}
0 commit comments