@@ -332,6 +332,14 @@ class logger
332
332
}
333
333
};
334
334
335
+ logger& LogInstance ()
336
+ {
337
+ // This is similar to Bitcoin's newer approach.
338
+ static logger* scraperlogger{new logger ()};
339
+ return *scraperlogger;
340
+ }
341
+
342
+
335
343
boost::gregorian::date logger::PrevArchiveCheckDate = boost::posix_time::from_time_t (GetAdjustedTime()).date();
336
344
CCriticalSection logger::cs_log;
337
345
@@ -361,11 +369,13 @@ void _log(logattribute eType, const std::string& sCall, const std::string& sMess
361
369
}
362
370
363
371
sOut = tfm::format (" %s [%s] <%s> : %s" , DateTimeStrFormat (" %x %H:%M:%S" , GetAdjustedTime ()), sType , sCall , sMessage );
364
- logger log;
372
+
373
+ // logger log;
374
+ logger& log = LogInstance ();
365
375
366
376
log.output (sOut );
367
377
368
- log.closelogfile ();
378
+ // log.closelogfile();
369
379
370
380
// Send to UI for log window.
371
381
uiInterface.NotifyScraperEvent (scrapereventtypes::Log, CT_NEW, sOut );
@@ -681,6 +691,9 @@ void ScraperApplyAppCacheEntries()
681
691
// It can also be called in "single shot" mode.
682
692
void Scraper (bool bSingleShot)
683
693
{
694
+ // Initialize log singleton.
695
+ LogInstance ();
696
+
684
697
// Initialize these while still single-threaded. They cannot be initialized during declaration because GetDataDir()
685
698
// gives the wrong value that early. If they are already initialized then leave them alone (because this function
686
699
// can be called in singleshot mode.
@@ -776,14 +789,14 @@ void Scraper(bool bSingleShot)
776
789
}
777
790
778
791
// Need the log archive check here, because we don't run housekeeping in this while loop.
779
- logger log;
792
+ logger& log = LogInstance () ;
780
793
781
794
fs::path plogfile_out;
782
795
783
796
if (log.archive (false , plogfile_out))
784
797
_log (logattribute::INFO, " Scraper" , " Archived scraper.log to " + plogfile_out.filename ().string ());
785
798
786
- log.closelogfile ();
799
+ // log.closelogfile();
787
800
788
801
sbage = SuperblockAge ();
789
802
_log (logattribute::INFO, " Scraper" , " Superblock not needed. age=" + std::to_string (sbage));
@@ -1040,14 +1053,14 @@ bool ScraperHousekeeping()
1040
1053
+ " , Popularity: " + std::to_string (network_hash.second ));
1041
1054
}
1042
1055
1043
- logger log;
1056
+ logger& log = LogInstance () ;
1044
1057
1045
1058
fs::path plogfile_out;
1046
1059
1047
1060
if (log.archive (false , plogfile_out))
1048
1061
_log (logattribute::INFO, " ScraperHousekeeping" , " Archived scraper.log to " + plogfile_out.filename ().string ());
1049
1062
1050
- log.closelogfile ();
1063
+ // log.closelogfile();
1051
1064
1052
1065
return true ;
1053
1066
}
@@ -4245,12 +4258,12 @@ UniValue archivescraperlog(const UniValue& params, bool fHelp)
4245
4258
" archivescraperlog takes no arguments and results in immediate archiving of the scraper log\n "
4246
4259
);
4247
4260
4248
- logger log;
4261
+ logger& log = LogInstance () ;
4249
4262
4250
4263
fs::path pfile_out;
4251
4264
bool ret = log.archive (true , pfile_out);
4252
4265
4253
- log.closelogfile ();
4266
+ // log.closelogfile();
4254
4267
4255
4268
return UniValue (ret);
4256
4269
}
0 commit comments