diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index ef9a3708a..c075d3cac 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -50,8 +50,7 @@ namespace MWDialogue DialogueManager::DialogueManager (const Compiler::Extensions& extensions, Translation::Storage& translationDataStorage) : mTranslationDataStorage(translationDataStorage) , mCompilerContext (MWScript::CompilerContext::Type_Dialogue) - , mErrorStream(std::cout.rdbuf()) - , mErrorHandler(mErrorStream) + , mErrorHandler() , mTalkedTo(false) , mTemporaryDispositionChange(0.f) , mPermanentDispositionChange(0.f) @@ -204,8 +203,7 @@ namespace MWDialogue if (!success) { - Log(Debug::Warning) - << "Warning: compiling failed (dialogue script)\n" << cmd << "\n\n"; + Log(Debug::Error) << "Error: compiling failed (dialogue script): \n" << cmd << "\n"; } return success; diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index 29a90082c..fad086183 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -33,7 +33,6 @@ namespace MWDialogue Translation::Storage& mTranslationDataStorage; MWScript::CompilerContext mCompilerContext; - std::ostream mErrorStream; Compiler::StreamErrorHandler mErrorHandler; MWWorld::Ptr mActor; diff --git a/apps/openmw/mwdialogue/scripttest.cpp b/apps/openmw/mwdialogue/scripttest.cpp index 791a4da7e..c3d7b12c7 100644 --- a/apps/openmw/mwdialogue/scripttest.cpp +++ b/apps/openmw/mwdialogue/scripttest.cpp @@ -28,8 +28,7 @@ void test(const MWWorld::Ptr& actor, int &compiled, int &total, const Compiler:: MWScript::CompilerContext compilerContext(MWScript::CompilerContext::Type_Dialogue); compilerContext.setExtensions(extensions); - std::ostream errorStream(std::cout.rdbuf()); - Compiler::StreamErrorHandler errorHandler(errorStream); + Compiler::StreamErrorHandler errorHandler; errorHandler.setWarningsMode (warningsMode); const MWWorld::Store& dialogues = MWBase::Environment::get().getWorld()->getStore().get(); @@ -84,8 +83,7 @@ void test(const MWWorld::Ptr& actor, int &compiled, int &total, const Compiler:: if (!success) { - Log(Debug::Warning) - << "compiling failed (dialogue script)\n" << info->mResultScript << "\n\n"; + Log(Debug::Error) << "Error: compiling failed (dialogue script): \n" << info->mResultScript << "\n"; } } } diff --git a/apps/openmw/mwscript/scriptmanagerimp.cpp b/apps/openmw/mwscript/scriptmanagerimp.cpp index 80496d6db..0dcf34afb 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.cpp +++ b/apps/openmw/mwscript/scriptmanagerimp.cpp @@ -25,7 +25,7 @@ namespace MWScript ScriptManager::ScriptManager (const MWWorld::ESMStore& store, Compiler::Context& compilerContext, int warningsMode, const std::vector& scriptBlacklist) - : mErrorHandler (std::cerr), mStore (store), + : mErrorHandler(), mStore (store), mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext), mOpcodesInstalled (false), mGlobalScripts (store) { @@ -72,8 +72,7 @@ namespace MWScript if (!Success) { - Log(Debug::Warning) - << "Warning: compiling failed: " << name; + Log(Debug::Error) << "Error: script compiling failed: " << name; } if (Success) diff --git a/components/compiler/streamerrorhandler.cpp b/components/compiler/streamerrorhandler.cpp index 04bee8adb..b5a3a8c9f 100644 --- a/components/compiler/streamerrorhandler.cpp +++ b/components/compiler/streamerrorhandler.cpp @@ -1,5 +1,9 @@ #include "streamerrorhandler.hpp" +#include + +#include + #include "tokenloc.hpp" namespace Compiler @@ -9,32 +13,47 @@ namespace Compiler void StreamErrorHandler::report (const std::string& message, const TokenLoc& loc, Type type) { + Debug::Level logLevel = Debug::Info; // Usually script warnings are not too important + if (type == ErrorMessage) + logLevel = Debug::Error; + + std::stringstream text; + if (type==ErrorMessage) - mStream << "error "; + text << "Error: "; else - mStream << "warning "; + text << "Warning: "; if (!mContext.empty()) - mStream << mContext << " "; + text << mContext << " "; + + text << "line " << loc.mLine+1 << ", column " << loc.mColumn+1 + << " (" << loc.mLiteral << "): " << message; - mStream - << "line " << loc.mLine+1 << ", column " << loc.mColumn+1 - << " (" << loc.mLiteral << ")" << std::endl - << " " << message << std::endl; + Log(logLevel) << text.str(); } // Report a file related error void StreamErrorHandler::report (const std::string& message, Type type) { + Debug::Level logLevel = Debug::Info; if (type==ErrorMessage) - mStream << "error "; + logLevel = Debug::Error; + + std::stringstream text; + + if (type==ErrorMessage) + text << "Error: "; else - mStream << "warning "; + text << "Warning: "; + + if (!mContext.empty()) + text << mContext << " "; + + text << "file: " << message << std::endl; - mStream - << "file:" << std::endl - << " " << message << std::endl; + Log(logLevel) << text.str(); } void StreamErrorHandler::setContext(const std::string &context) @@ -42,5 +61,5 @@ namespace Compiler mContext = context; } - StreamErrorHandler::StreamErrorHandler (std::ostream& ErrorStream) : mStream (ErrorStream) {} + StreamErrorHandler::StreamErrorHandler() {} } diff --git a/components/compiler/streamerrorhandler.hpp b/components/compiler/streamerrorhandler.hpp index d287833ee..e203a6ef7 100644 --- a/components/compiler/streamerrorhandler.hpp +++ b/components/compiler/streamerrorhandler.hpp @@ -7,12 +7,10 @@ namespace Compiler { - /// \brief Error handler implementation: Write errors into stream + /// \brief Error handler implementation: Write errors into logging stream class StreamErrorHandler : public ErrorHandler { - std::ostream& mStream; - std::string mContext; // not implemented @@ -32,7 +30,7 @@ namespace Compiler // constructors - StreamErrorHandler (std::ostream& ErrorStream); + StreamErrorHandler (); ///< constructor }; }