Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boost log to file #172

Merged
merged 23 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
64d8ced
main.cpp: Switch Boost Logging to go to a file
stephengtuggy Jul 7, 2020
6122e87
basecomputer.cpp: remove last references to vs_dprintf, stderr, etc.
stephengtuggy Jul 9, 2020
2acbbd8
missile_generic.cpp: Remove last vestiges of vs_dprintf, fprintf, etc.
stephengtuggy Jul 9, 2020
904f417
stardate.cpp: finish replacing vs_dprintf with BOOST_LOG_TRIVIAL
stephengtuggy Jul 9, 2020
023805d
savegame.cpp: Replaced vs_dprintf with BOOST_LOG_TRIVIAL, but more to go
stephengtuggy Jul 9, 2020
d0a5e35
main.cpp: log to $HOME/.vegastrike/logs; and to console, just fatal errs
stephengtuggy Jul 9, 2020
5a47416
Merge branch 'master' into boost_log_to_file
stephengtuggy Jul 9, 2020
d4a8140
Merge branch 'master' into boost_log_to_file
stephengtuggy Jul 14, 2020
5f0277f
Make pFileLogSink a global variable; flush it when hard exiting
stephengtuggy Jul 17, 2020
6854bd4
Finish converting main.cpp to use Boost logging
stephengtuggy Jul 18, 2020
e48ce29
Merge remote-tracking branch 'vegastrike/master' into boost_log_to_file
stephengtuggy Jul 25, 2020
1d65680
minor: whitespace
stephengtuggy Jul 25, 2020
2a57573
Split initLogging into 2 parts; vsfilesystem.cpp Boost logging
stephengtuggy Jul 25, 2020
860a22b
basecomputer.cpp: Fix a couple of boost::format strings; flush log(s)
stephengtuggy Jul 25, 2020
0759614
Merge remote-tracking branch 'vegastrike/master' into boost_log_to_file
stephengtuggy Jul 26, 2020
e60810a
Merge remote-tracking branch 'vegastrike/master' into boost_log_to_file
stephengtuggy Jul 26, 2020
6e5a177
Shift responsibility for flushing logs, incl. console, to fn flushLogs()
stephengtuggy Jul 27, 2020
1450e46
minor: whitespace
stephengtuggy Jul 27, 2020
459d20c
Merge remote-tracking branch 'vegastrike/master' into boost_log_to_file
stephengtuggy Jul 27, 2020
79177e5
Oops! Accidentally made flushLogs() call itself (infinite recursion)
stephengtuggy Jul 27, 2020
3f1abf5
cmd/ai/script.cpp,cmd/script/director.cpp: Boost-log more msgs
stephengtuggy Jul 27, 2020
7039134
Flush logs before exit()-ing, wherever possible
stephengtuggy Jul 27, 2020
c8abcb8
More logging and flushing
stephengtuggy Jul 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions engine/src/cmd/ai/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static HardCodedMap MakeHardCodedScripts()
tmp.insert( MyPair( "roll perpendicular slow", &RollFacePerpendicularSlow ) );
tmp.insert( MyPair( "roll perpendicular fast", &RollFacePerpendicularFast ) );
if (tmp.find("roll perpendicular fast")==tmp.end()){
exit(1);
VSExit(1);
}
return tmp;
}
Expand Down Expand Up @@ -104,14 +104,14 @@ float& AIScript::topf()
{
if ( !xml->floats.size() ) {
xml->floats.push( xml->defaultf );
VSFileSystem::vs_fprintf( stderr, "\nERROR: Float stack is empty... Will return %f\n", xml->defaultf );
BOOST_LOG_TRIVIAL(error) << boost::format("ERROR: Float stack is empty... Will return %1%") % xml->defaultf;
}
return xml->floats.top();
}
void AIScript::popf()
{
if (xml->floats.size() <= 0) {
VSFileSystem::vs_fprintf( stderr, "\nERROR: Float stack is empty... Will not delete\n" );
BOOST_LOG_TRIVIAL(error) << "ERROR: Float stack is empty... Will not delete";
return;
}
xml->floats.pop();
Expand All @@ -120,18 +120,18 @@ QVector& AIScript::topv()
{
if ( !xml->vectors.size() ) {
xml->vectors.push( xml->defaultvec );
VSFileSystem::vs_fprintf( stderr,
"\nERROR: Vector stack is empty... Will return <%f, %f, %f>\n",
xml->defaultvec.i,
xml->defaultvec.j,
xml->defaultvec.k );
BOOST_LOG_TRIVIAL(error) << boost::format(
"ERROR: Vector stack is empty... Will return <%1%, %2%, %3%>")
% xml->defaultvec.i
% xml->defaultvec.j
% xml->defaultvec.k;
}
return xml->vectors.top();
}
void AIScript::popv()
{
if (xml->vectors.size() <= 0) {
VSFileSystem::vs_fprintf( stderr, "\nERROR: Vector stack is empty... Will not delete\n" );
BOOST_LOG_TRIVIAL(error) << "ERROR: Vector stack is empty... Will not delete";
return;
}
xml->vectors.pop();
Expand Down Expand Up @@ -270,11 +270,11 @@ void AIScript::beginElement( const string &name, const AttributeList &attributes
xml->itts = false;
Unit *tmp;
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "0" );
BOOST_LOG_TRIVIAL(debug) << "0";
#endif
Names elem = (Names) element_map.lookup( name );
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "1%x ", &elem );
BOOST_LOG_TRIVIAL(debug) << boost::format("1%1$x ") % &elem;
#endif
AttributeList::const_iterator iter;
switch (elem)
Expand Down Expand Up @@ -308,7 +308,7 @@ void AIScript::beginElement( const string &name, const AttributeList &attributes
break;
case DUPLIC:
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "1%x ", &elem );
BOOST_LOG_TRIVIAL(debug) << boost::format("1%1$x ") % &elem;
#endif
xml->vectors.pop(); //get rid of dummy vector pushed on above
xml->vectors.push( xml->vectors.top() );
Expand Down Expand Up @@ -374,7 +374,7 @@ void AIScript::beginElement( const string &name, const AttributeList &attributes
break;
case FACETARGET:
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "ft" );
BOOST_LOG_TRIVIAL(debug) << "ft";
#endif
xml->unitlevel++;
xml->acc = 3;
Expand All @@ -396,7 +396,7 @@ void AIScript::beginElement( const string &name, const AttributeList &attributes
}
}
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "eft" );
BOOST_LOG_TRIVIAL(debug) << "eft";
#endif

break;
Expand Down Expand Up @@ -478,7 +478,7 @@ void AIScript::beginElement( const string &name, const AttributeList &attributes
case MATCHANG:
case MATCHVEL:
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "mlv" );
BOOST_LOG_TRIVIAL(debug) << "mlv";
#endif

xml->unitlevel++;
Expand All @@ -500,7 +500,7 @@ void AIScript::beginElement( const string &name, const AttributeList &attributes
}
}
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "emlv " );
BOOST_LOG_TRIVIAL(debug) << "emlv ";
#endif

break;
Expand Down Expand Up @@ -666,7 +666,7 @@ void AIScript::endElement( const string &name )
topv() = -topv();
break;
case MOVETO:
VSFileSystem::vs_fprintf( stderr, "Moveto <%f,%f,%f>", topv().i, topv().j, topv().k );
BOOST_LOG_TRIVIAL(debug) << boost::format("Moveto <%1%,%2%,%3%>") % topv().i % topv().j % topv().k;
xml->unitlevel--;
xml->orders.push_back( new Orders::MoveTo( topv(), xml->afterburn, xml->acc ) );
popv();
Expand Down Expand Up @@ -772,9 +772,9 @@ void AIScript::LoadXML()
RollLeft( this, parent );
}
if (aidebug > 1) {
VSFileSystem::vs_fprintf( stderr, "%f using hcs %s for %s threat %f\n",
mission->getGametime(), filename, parent->name.get().c_str(),
parent->GetComputerData().threatlevel );
BOOST_LOG_TRIVIAL(debug) << boost::format("%1% using hcs %2% for %3% threat %4%")
% mission->getGametime() % filename % parent->name
% parent->GetComputerData().threatlevel;
}
if ( _Universe->isPlayerStarship( parent->Target() ) ) {
float value;
Expand Down Expand Up @@ -804,32 +804,32 @@ void AIScript::LoadXML()
return;
} else {
if (aidebug > 1)
VSFileSystem::vs_fprintf( stderr, "using soft coded script %s", filename );
BOOST_LOG_TRIVIAL(debug) << boost::format("using soft coded script %1%") % filename;
if (aidebug > 0)
UniverseUtil::IOmessage( 0, parent->name, "all", string( "FAILED(or missile) script " )+string(
filename )+" threat "+XMLSupport::tostring( parent->GetComputerData().threatlevel ) );
}
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "chd" );
BOOST_LOG_TRIVIAL(debug) << "chd";
#endif

#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "echd" );
BOOST_LOG_TRIVIAL(debug) << "echd";
#endif
VSFile f;
VSError err = f.OpenReadOnly( filename, AiFile );
#ifdef AIDBG
VSFileSystem::vs_fprintf( stderr, "backup " );
BOOST_LOG_TRIVIAL(debug) << "backup ";
#endif
if (err > Ok) {
VSFileSystem::vs_fprintf( stderr, "cannot find AI script %s\n", filename );
BOOST_LOG_TRIVIAL(error) << boost::format("cannot find AI script %1%") % filename;
if (hard_coded_scripts.find(filename)!=hard_coded_scripts.end()) {
assert(0);
}
return;
}
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "nxml" );
BOOST_LOG_TRIVIAL(debug) << "nxml";
#endif
xml = new AIScriptXML;
xml->unitlevel = 0;
Expand All @@ -839,48 +839,48 @@ void AIScript::LoadXML()
xml->defaultvec = QVector( 0, 0, 0 );
xml->defaultf = 0;
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "parscrea" );
BOOST_LOG_TRIVIAL(debug) << "parscrea";
#endif
XML_Parser parser = XML_ParserCreate( NULL );
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "usdat %x", parser );
BOOST_LOG_TRIVIAL(debug) << boost::format("usdat %1$x") % parser;
#endif
XML_SetUserData( parser, this );
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "elha" );
BOOST_LOG_TRIVIAL(debug) << "elha";
#endif
XML_SetElementHandler( parser, &AIScript::beginElement, &AIScript::endElement );
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "do" );
BOOST_LOG_TRIVIAL(debug) << "do";
#endif
XML_Parse( parser, ( f.ReadFull() ).c_str(), f.Size(), 1 );
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "%xxml_free", parser );
fflush( stderr );
BOOST_LOG_TRIVIAL(debug) << boost::format("%1$xxml_free") % parser;
VSFileSystem::flushLogs();
#endif
XML_ParserFree( parser );
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "xml_freed" );
BOOST_LOG_TRIVIAL(debug) << "xml_freed";
#endif
f.Close();
for (unsigned int i = 0; i < xml->orders.size(); i++) {
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "parset" );
BOOST_LOG_TRIVIAL(debug) << "parset";
#endif
xml->orders[i]->SetParent( parent );
EnqueueOrder( xml->orders[i] );
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "cachunkx" );
BOOST_LOG_TRIVIAL(debug) << "cachunkx";
#endif
}
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "xml%x", xml );
fflush( stderr );
BOOST_LOG_TRIVIAL(debug) << boost::format("xml%1$x") % xml;
VSFileSystem::flushLogs();
#endif
delete xml;
#ifdef BIDBG
VSFileSystem::vs_fprintf( stderr, "\\xml\n" );
fflush( stderr );
BOOST_LOG_TRIVIAL(debug) << "\\xml\n";
VSFileSystem::flushLogs();
#endif
}

Expand All @@ -893,14 +893,14 @@ AIScript::AIScript( const char *scriptname ) : Order( Order::MOVEMENT|Order::FAC
AIScript::~AIScript()
{
#ifdef ORDERDEBUG
VSFileSystem::vs_fprintf( stderr, "sc%x", this );
fflush( stderr );
BOOST_LOG_TRIVIAL(debug) << boost::format("sc%1$x") % this;
VSFileSystem::flushLogs();
#endif
if (filename)
delete[] filename;
#ifdef ORDERDEBUG
VSFileSystem::vs_fprintf( stderr, "sc\n" );
fflush( stderr );
BOOST_LOG_TRIVIAL(debug) << "sc";
VSFileSystem::flushLogs();
#endif
}

Expand All @@ -909,14 +909,14 @@ void AIScript::Execute()
if (filename) {
LoadXML();
#ifdef ORDERDEBUG
VSFileSystem::vs_fprintf( stderr, "fn%x", this );
fflush( stderr );
BOOST_LOG_TRIVIAL(debug) << boost::format("fn%1$x") % this;
VSFileSystem::flushLogs();
#endif
delete[] filename;
filename = NULL;
#ifdef ORDERDEBUG
VSFileSystem::vs_fprintf( stderr, "fn" );
fflush( stderr );
BOOST_LOG_TRIVIAL(debug) << "fn";
VSFileSystem::flushLogs();
#endif
}
Order::Execute();
Expand Down
39 changes: 10 additions & 29 deletions engine/src/cmd/basecomputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ void BaseComputer::loadMissionsMasterList( TransactionList &tlist )
Unit *unit = _Universe->AccessCockpit()->GetParent();
int playerNum = UnitUtil::isPlayerStarship( unit );
if (playerNum < 0) {
VSFileSystem::vs_fprintf( stderr, "Docked ship not a player." );
BOOST_LOG_TRIVIAL(error) << "Docked ship not a player.";
return;
}
//Number of strings to look at. And make sure they match!
Expand Down Expand Up @@ -3849,17 +3849,10 @@ Cargo CreateCargoForOwnerStarship( const Cockpit *cockpit, const Unit *base, int
jumps);
BOOST_LOG_TRIVIAL(trace) << boost::format("Player ship needs transport from %1% to %2% across %3% systems") % locationBaseName %
destinationSystemName % jumps.size();
// VSFileSystem::vs_dprintf(3, "Player ship needs transport from %s to %s across %d systems",
// locationBaseName.c_str(),
// destinationSystemName.c_str(),
// jumps.size());
cargo.price += shipping_price_perjump * (jumps.size() - 1);
} else if (needsInsysTransport) {
BOOST_LOG_TRIVIAL(trace) << boost::format("Player ship needs insys transport from %1% to %2%") % locationBaseName %
destinationBaseName;
// VSFileSystem::vs_dprintf(3, "Player ship needs insys transport from %s to %s",
// locationBaseName.c_str(),
// destinationBaseName.c_str());
cargo.price += shipping_price_insys;
}

Expand Down Expand Up @@ -3984,9 +3977,6 @@ void trackPrice(int whichplayer, const Cargo &item, float price, const string &s

BOOST_LOG_TRIVIAL(info) << boost::format("Ranking item %1%/%2% at %3%/%4%") % item.category.get() % item.content.get() % systemName %
baseName;
// VSFileSystem::vs_dprintf(1, "Ranking item %s/%s at %s/%s\n",
// item.category.get().c_str(), item.content.get().c_str(),
// systemName.c_str(), baseName.c_str());

// Recorded prices are always sorted, so we first do a quick check to avoid
// triggering savegame serialization without reason
Expand Down Expand Up @@ -4113,43 +4103,36 @@ void trackPrice(int whichplayer, const Cargo &item, float price, const string &s

BOOST_LOG_TRIVIAL(info) << "Tracking data:";
BOOST_LOG_TRIVIAL(info) << boost::format(" highest locs: (%1%)") % recordedHighestLocs.size();
// VSFileSystem::vs_dprintf(1,"Tracking data:\n");
// VSFileSystem::vs_dprintf(1," highest locs: (%d)\n", recordedHighestLocs.size());
{
for (size_t i = 0; i < recordedHighestLocs.size(); ++i) {
BOOST_LOG_TRIVIAL(info) << boost::format(" %1% : %2%") % i % recordedHighestLocs[i];
// VSFileSystem::vs_dprintf(1, " %d : %s\n", i, recordedHighestLocs[i].c_str());
}
}

//BOOST_LOG_TRIVIAL(info) << boost::format(" highest prices: (%1%)") % recordedHighestPrices.size();
VSFileSystem::vs_dprintf(1," highest prices: (%d)\n", recordedHighestPrices.size());
BOOST_LOG_TRIVIAL(info) << boost::format(" highest prices: (%1%)") % recordedHighestPrices.size();
{
for (size_t i = 0; i < recordedHighestPrices.size(); ++i) {
BOOST_LOG_TRIVIAL(info) << boost::format(" %1% : %2$.2f") % i % recordedHighestPrices[i];
// VSFileSystem::vs_dprintf(1, " %d : %.2f\n", i, recordedHighestPrices[i]);
// POSIX-printf style
BOOST_LOG_TRIVIAL(info) << boost::format(" %1$d : %2$.2f") % i % recordedHighestPrices[i];
}
}

//BOOST_LOG_TRIVIAL(info) << boost::format(" lowest locs: (%1%)") % recordedLowestLocs.size();
VSFileSystem::vs_dprintf(1," lowest locs: (%d)\n", recordedLowestLocs.size());
BOOST_LOG_TRIVIAL(info) << boost::format(" lowest locs: (%1%)") % recordedLowestLocs.size();
{
for (size_t i = 0; i < recordedLowestLocs.size(); ++i) {
BOOST_LOG_TRIVIAL(info) << boost::format(" %1% : %2%") % i % recordedLowestLocs[i];
// VSFileSystem::vs_dprintf(1, " %d : %s\n", i, recordedLowestLocs[i].c_str());
}
}

//BOOST_LOG_TRIVIAL(info) << boost::format(" lowest prices: (%1%)") % recordedLowestPrices.size();
VSFileSystem::vs_dprintf(1," lowest prices: (%d)\n", recordedLowestPrices.size());
BOOST_LOG_TRIVIAL(info) << boost::format(" lowest prices: (%1%)") % recordedLowestPrices.size();
{
for (size_t i = 0; i < recordedLowestPrices.size(); ++i) {
BOOST_LOG_TRIVIAL(info) << boost::format(" %1% : %2$.2f") % i % recordedLowestPrices[i];
// VSFileSystem::vs_dprintf(1, " %d : %.2f\n", i, recordedLowestPrices[i]);
// POSIX-printf style
BOOST_LOG_TRIVIAL(info) << boost::format(" %1$d : %2$.2f") % i % recordedLowestPrices[i];
}
}

fflush(stderr);
VSFileSystem::flushLogs();

highest.clear();
highest.resize(recordedHighestPrices.size());
Expand All @@ -4160,7 +4143,6 @@ void trackPrice(int whichplayer, const Cargo &item, float price, const string &s
text += " (at " + recordedHighestLocs[i] + ")";

BOOST_LOG_TRIVIAL(info) << boost::format("Highest item %1%") % text;
// VSFileSystem::vs_dprintf(1, "Highest item %s\n", text.c_str());
}
}

Expand All @@ -4173,7 +4155,6 @@ void trackPrice(int whichplayer, const Cargo &item, float price, const string &s
text += " (at " + recordedLowestLocs[i] + ")";

BOOST_LOG_TRIVIAL(info) << boost::format("Lowest item %1%") % text;
// VSFileSystem::vs_dprintf(1, "Lowest item %s\n", text.c_str());
}
}
}
Expand Down Expand Up @@ -4790,7 +4771,7 @@ void showUnitStats( Unit *playerUnit, string &text, int subunitlevel, int mode,
if (!mode) {
text += conversionBuffer;
text += " radians/second^2#n#"+expstatcolor+" (yaw, pitch, roll)#-c";
} else if (MODIFIES(replacement_mode, playerUnit, blankUnit, limits.yaw)) {
} else if (MODIFIES(replacement_mode, playerUnit, blankUnit, limits.yaw)) {
switch (replacement_mode)
{
case 0: //Replacement or new Module
Expand Down
4 changes: 2 additions & 2 deletions engine/src/cmd/bolt_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ void BoltDestroyGeneric( Bolt *whichbolt, unsigned int index, int decal, bool is
(*vec)[index] = vec->back(); //just a memcopy, yo
vec->pop_back(); //pop that back up
} else {
VSFileSystem::vs_fprintf( stderr, "Bolt Fault Nouveau! Not found in draw queue! No Chance to recover\n" );
fflush( stderr );
BOOST_LOG_TRIVIAL(fatal) << "Bolt Fault Nouveau! Not found in draw queue! No Chance to recover";
VSFileSystem::flushLogs();
assert( 0 );
}
}
Expand Down
Loading