Skip to content

Commit

Permalink
Merge pull request #1872 from akortunov/extended_logging
Browse files Browse the repository at this point in the history
Use new logging system
  • Loading branch information
psi29a committed Aug 16, 2018
2 parents fa1f3ec + 5a4d0ce commit dcd3810
Show file tree
Hide file tree
Showing 102 changed files with 470 additions and 448 deletions.
10 changes: 5 additions & 5 deletions apps/opencs/editor.cpp
Expand Up @@ -5,8 +5,8 @@
#include <QLocalSocket>
#include <QMessageBox>

#include <components/debug/debuglog.hpp>
#include <components/fallback/validate.hpp>

#include <components/nifosg/nifloader.hpp>

#include "model/doc/document.hpp"
Expand Down Expand Up @@ -294,7 +294,7 @@ bool CS::Editor::makeIPCServer()
mLock = boost::interprocess::file_lock(mPid.string().c_str());
if(!mLock.try_lock())
{
std::cerr << "OpenCS already running." << std::endl;
Log(Debug::Error) << "Error: OpenMW-CS is already running.";
return false;
}

Expand All @@ -317,17 +317,17 @@ bool CS::Editor::makeIPCServer()
if(boost::filesystem::exists(fullPath.toUtf8().constData()))
{
// TODO: compare pid of the current process with that in the file
std::cout << "Detected unclean shutdown." << std::endl;
Log(Debug::Info) << "Detected unclean shutdown.";
// delete the stale file
if(remove(fullPath.toUtf8().constData()))
std::cerr << "ERROR removing stale connection file" << std::endl;
Log(Debug::Error) << "Error: can not remove stale connection file.";
}
}
}

catch(const std::exception& e)
{
std::cerr << "ERROR " << e.what() << std::endl;
Log(Debug::Error) << "Error: " << e.what();
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions apps/opencs/main.cpp
@@ -1,7 +1,6 @@
#include "editor.hpp"

#include <exception>
#include <iostream>
#include <string>

#include <QApplication>
Expand Down Expand Up @@ -31,7 +30,7 @@ class Application : public QApplication
}
catch (const std::exception& exception)
{
std::cerr << "An exception has been caught: " << exception.what() << std::endl;
Log(Debug::Error) << "An exception has been caught: " << exception.what();
}

return false;
Expand Down
5 changes: 3 additions & 2 deletions apps/opencs/model/doc/document.cpp
Expand Up @@ -2,7 +2,6 @@

#include <cassert>
#include <fstream>
#include <iostream>

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
Expand All @@ -13,6 +12,8 @@
#include <components/files/configurationmanager.hpp>
#endif

#include <components/debug/debuglog.hpp>

void CSMDoc::Document::addGmsts()
{
for (size_t i=0; i < CSMWorld::DefaultGmsts::FloatCount; ++i)
Expand Down Expand Up @@ -435,7 +436,7 @@ void CSMDoc::Document::modificationStateChanged (bool clean)
void CSMDoc::Document::reportMessage (const CSMDoc::Message& message, int type)
{
/// \todo find a better way to get these messages to the user.
std::cout << message.mMessage << std::endl;
Log(Debug::Info) << message.mMessage;
}

void CSMDoc::Document::operationDone2 (int type, bool failed)
Expand Down
10 changes: 5 additions & 5 deletions apps/opencs/model/world/refcollection.cpp
@@ -1,8 +1,8 @@
#include "refcollection.hpp"

#include <sstream>
#include <iostream>

#include <components/debug/debuglog.hpp>
#include <components/misc/stringops.hpp>
#include <components/esm/loadcell.hpp>

Expand Down Expand Up @@ -58,10 +58,10 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
// message
if (index.first != mref.mTarget[0] || index.second != mref.mTarget[1])
{
std::cerr << "The Position of moved ref "
<< ref.mRefID << " does not match the target cell" << std::endl;
std::cerr << "Position: #" << index.first << " " << index.second
<<", Target #"<< mref.mTarget[0] << " " << mref.mTarget[1] << std::endl;
Log(Debug::Warning) << "Warning: the Position of moved ref "
<< ref.mRefID << " does not match the target cell";
Log(Debug::Warning) << "Position: #" << index.first << " " << index.second
<<", Target #"<< mref.mTarget[0] << " " << mref.mTarget[1];

stream.clear();
stream << "#" << mref.mTarget[0] << " " << mref.mTarget[1];
Expand Down
4 changes: 2 additions & 2 deletions apps/opencs/view/render/object.cpp
@@ -1,7 +1,6 @@
#include "object.hpp"

#include <stdexcept>
#include <iostream>

#include <osg/Depth>
#include <osg/Group>
Expand All @@ -24,6 +23,7 @@
#include "../../model/world/cellcoordinates.hpp"
#include "../../model/prefs/state.hpp"

#include <components/debug/debuglog.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/lightutil.hpp>
#include <components/sceneutil/lightmanager.hpp>
Expand Down Expand Up @@ -133,7 +133,7 @@ void CSVRender::Object::update()
catch (std::exception& e)
{
// TODO: use error marker mesh
std::cerr << e.what() << std::endl;
Log(Debug::Error) << e.what();
}
}

Expand Down
34 changes: 17 additions & 17 deletions apps/openmw/engine.cpp
Expand Up @@ -10,6 +10,8 @@

#include <SDL.h>

#include <components/debug/debuglog.hpp>

#include <components/misc/rng.hpp>

#include <components/vfs/manager.hpp>
Expand Down Expand Up @@ -61,7 +63,7 @@ namespace
void checkSDLError(int ret)
{
if (ret != 0)
std::cerr << "SDL error: " << SDL_GetError() << std::endl;
Log(Debug::Error) << "SDL error: " << SDL_GetError();
}
}

Expand Down Expand Up @@ -189,7 +191,7 @@ bool OMW::Engine::frame(float frametime)
}
catch (const std::exception& e)
{
std::cerr << "Error in frame: " << e.what() << std::endl;
Log(Debug::Error) << "Error in frame: " << e.what();
}
return true;
}
Expand Down Expand Up @@ -364,7 +366,7 @@ void OMW::Engine::createWindow(Settings::Manager& settings)
// Try with a lower AA
if (antialiasing > 0)
{
std::cout << "Note: " << antialiasing << "x antialiasing not supported, trying " << antialiasing/2 << std::endl;
Log(Debug::Warning) << "Warning: " << antialiasing << "x antialiasing not supported, trying " << antialiasing/2;
antialiasing /= 2;
Settings::Manager::setInt("antialiasing", "Video", antialiasing);
checkSDLError(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing));
Expand All @@ -373,7 +375,7 @@ void OMW::Engine::createWindow(Settings::Manager& settings)
else
{
std::stringstream error;
error << "Failed to create SDL window: " << SDL_GetError() << std::endl;
error << "Failed to create SDL window: " << SDL_GetError();
throw std::runtime_error(error.str());
}
}
Expand Down Expand Up @@ -420,16 +422,16 @@ void OMW::Engine::setWindowIcon()
std::string windowIcon = (mResDir / "mygui" / "openmw.png").string();
windowIconStream.open(windowIcon, std::ios_base::in | std::ios_base::binary);
if (windowIconStream.fail())
std::cerr << "Error: Failed to open " << windowIcon << std::endl;
Log(Debug::Error) << "Error: Failed to open " << windowIcon;
osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension("png");
if (!reader)
{
std::cerr << "Error: Failed to read window icon, no png readerwriter found" << std::endl;
Log(Debug::Error) << "Error: Failed to read window icon, no png readerwriter found";
return;
}
osgDB::ReaderWriter::ReadResult result = reader->readImage(windowIconStream);
if (!result.success())
std::cerr << "Error: Failed to read " << windowIcon << ": " << result.message() << " code " << result.status() << std::endl;
Log(Debug::Error) << "Error: Failed to read " << windowIcon << ": " << result.message() << " code " << result.status();
else
{
osg::ref_ptr<osg::Image> image = result.getImage();
Expand Down Expand Up @@ -564,21 +566,19 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
{
std::pair<int, int> result = mEnvironment.getScriptManager()->compileAll();
if (result.first)
std::cout
Log(Debug::Info)
<< "compiled " << result.second << " of " << result.first << " scripts ("
<< 100*static_cast<double> (result.second)/result.first
<< "%)"
<< std::endl;
<< "%)";
}
if (mCompileAllDialogue)
{
std::pair<int, int> result = MWDialogue::ScriptTest::compileAll(&mExtensions, mWarningsMode);
if (result.first)
std::cout
Log(Debug::Info)
<< "compiled " << result.second << " of " << result.first << " dialogue script/actor combinations a("
<< 100*static_cast<double> (result.second)/result.first
<< "%)"
<< std::endl;
<< "%)";
}
}

Expand Down Expand Up @@ -614,14 +614,14 @@ class WriteScreenshotToFileOperation : public osgViewer::ScreenCaptureHandler::C
osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension(mScreenshotFormat);
if (!readerwriter)
{
std::cerr << "Error: Can't write screenshot, no '" << mScreenshotFormat << "' readerwriter found" << std::endl;
Log(Debug::Error) << "Error: Can't write screenshot, no '" << mScreenshotFormat << "' readerwriter found";
return;
}

osgDB::ReaderWriter::WriteResult result = readerwriter->writeImage(image, outStream);
if (!result.success())
{
std::cerr << "Error: Can't write screenshot: " << result.message() << " code " << result.status() << std::endl;
Log(Debug::Error) << "Error: Can't write screenshot: " << result.message() << " code " << result.status();
}
}

Expand All @@ -636,7 +636,7 @@ void OMW::Engine::go()
{
assert (!mContentFiles.empty());

std::cout << "OSG version: " << osgGetVersion() << std::endl;
Log(Debug::Info) << "OSG version: " << osgGetVersion();

// Load settings
Settings::Manager settings;
Expand Down Expand Up @@ -738,7 +738,7 @@ void OMW::Engine::go()
// Save user settings
settings.saveUser(settingspath);

std::cout << "Quitting peacefully." << std::endl;
Log(Debug::Info) << "Quitting peacefully.";
}

void OMW::Engine::setCompileAll (bool all)
Expand Down
8 changes: 3 additions & 5 deletions apps/openmw/main.cpp
@@ -1,5 +1,3 @@
#include <iostream>

#include <components/version/version.hpp>
#include <components/files/configurationmanager.hpp>
#include <components/files/escape.hpp>
Expand Down Expand Up @@ -202,8 +200,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
StringsVector content = variables["content"].as<Files::EscapeStringVector>().toStdStringVector();
if (content.empty())
{
std::cout << "No content file given (esm/esp, nor omwgame/omwaddon). Aborting..." << std::endl;
return false;
Log(Debug::Error) << "No content file given (esm/esp, nor omwgame/omwaddon). Aborting...";
return false;
}

StringsVector::const_iterator it(content.begin());
Expand All @@ -217,7 +215,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
engine.setCell(variables["start"].as<Files::EscapeHashString>().toStdString());
engine.setSkipMenu (variables["skip-menu"].as<bool>(), variables["new-game"].as<bool>());
if (!variables["skip-menu"].as<bool>() && variables["new-game"].as<bool>())
std::cerr << "Warning: new-game used without skip-menu -> ignoring it" << std::endl;
Log(Debug::Warning) << "Warning: new-game used without skip-menu -> ignoring it";

// scripts
engine.setCompileAll(variables["script-all"].as<bool>());
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwclass/creature.cpp
@@ -1,7 +1,7 @@
#include "creature.hpp"

#include <components/misc/rng.hpp>

#include <components/debug/debuglog.hpp>
#include <components/esm/loadcrea.hpp>
#include <components/esm/creaturestate.hpp>
#include <components/settings/settings.hpp>
Expand Down Expand Up @@ -146,7 +146,7 @@ namespace MWClass
if (const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(*iter))
data->mCreatureStats.getSpells().add (spell);
else /// \todo add option to make this a fatal error message pop-up, but default to warning for vanilla compatibility
std::cerr << "Warning: ignoring nonexistent spell '" << *iter << "' on creature '" << ref->mBase->mId << "'" << std::endl;
Log(Debug::Warning) << "Warning: ignoring nonexistent spell '" << *iter << "' on creature '" << ref->mBase->mId << "'";
}

// inventory
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwclass/npc.cpp
Expand Up @@ -4,6 +4,7 @@

#include <components/misc/rng.hpp>

#include <components/debug/debuglog.hpp>
#include <components/esm/loadmgef.hpp>
#include <components/esm/loadnpc.hpp>
#include <components/esm/npcstate.hpp>
Expand Down Expand Up @@ -365,7 +366,7 @@ namespace MWClass
if (const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(*iter))
data->mNpcStats.getSpells().add (spell);
else
std::cerr << "Warning: ignoring nonexistent race power '" << *iter << "' on NPC '" << ref->mBase->mId << "'" << std::endl;
Log(Debug::Warning) << "Warning: ignoring nonexistent race power '" << *iter << "' on NPC '" << ref->mBase->mId << "'";
}

if (!ref->mBase->mFaction.empty())
Expand Down Expand Up @@ -395,7 +396,7 @@ namespace MWClass
else
{
/// \todo add option to make this a fatal error message pop-up, but default to warning for vanilla compatibility
std::cerr << "Warning: ignoring nonexistent spell '" << *iter << "' on NPC '" << ref->mBase->mId << "'" << std::endl;
Log(Debug::Warning) << "Warning: ignoring nonexistent spell '" << *iter << "' on NPC '" << ref->mBase->mId << "'";
}
}

Expand Down
13 changes: 6 additions & 7 deletions apps/openmw/mwdialogue/dialoguemanagerimp.cpp
Expand Up @@ -5,7 +5,8 @@
#include <algorithm>
#include <iterator>
#include <list>
#include <iostream>

#include <components/debug/debuglog.hpp>

#include <components/esm/loaddial.hpp>
#include <components/esm/loadinfo.hpp>
Expand Down Expand Up @@ -203,16 +204,14 @@ namespace MWDialogue
}
catch (const std::exception& error)
{
std::cerr << std::string ("Dialogue error: An exception has been thrown: ") + error.what() << std::endl;
Log(Debug::Error) << std::string ("Dialogue error: An exception has been thrown: ") + error.what();
success = false;
}

if (!success)
{
std::cerr
<< "Warning: compiling failed (dialogue script)" << std::endl
<< cmd
<< std::endl << std::endl;
Log(Debug::Warning)
<< "Warning: compiling failed (dialogue script)\n" << cmd << "\n\n";
}

return success;
Expand All @@ -232,7 +231,7 @@ namespace MWDialogue
}
catch (const std::exception& error)
{
std::cerr << std::string ("Dialogue error: An exception has been thrown: ") + error.what() << std::endl;
Log(Debug::Error) << std::string ("Dialogue error: An exception has been thrown: ") + error.what();
}
}
}
Expand Down

0 comments on commit dcd3810

Please sign in to comment.