1 /***************************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2013 PariahSoft LLC **
5 ***************************************/
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 #include <Gosu/Timing.hpp>
31 #include "client-conf.h"
34 #include "python-bindings-template.cpp"
38 #include "os-windows.h"
45 static verbosity_t verb
= V_NORMAL
;
47 static unsigned long startTime
;
49 static std::string
& chomp(std::string
& str
)
51 std::string::size_type notwhite
= str
.find_last_not_of(" \t\n\r");
52 str
.erase(notwhite
+ 1);
56 static std::string
ts()
58 unsigned long now
= Gosu::milliseconds();
60 std::ostringstream ts
;
63 ts
<< (now
- startTime
) / (long double)1000.0;
64 return "[" + ts
.str() + "] ";
69 startTime
= Gosu::milliseconds();
73 void Log::setVerbosity(verbosity_t v
)
78 void Log::info(std::string domain
, std::string msg
)
80 std::string str
= ts() + "Info [" + domain
+ "] - " + chomp(msg
);
82 std::cout
<< str
<< std::endl
;
85 void Log::err(std::string domain
, std::string msg
)
87 if (conf
.halting
== HALT_ERROR
) {
88 Log::fatal(domain
, msg
);
91 std::string str
= ts() + "Error [" + domain
+ "] - " + chomp(msg
);
93 PyErr_SetString(PyExc_RuntimeError
, str
.c_str());
97 std::cerr
<< str
<< std::endl
;
99 wMessageBox("Tsunagari - Error", str
);
102 macMessageBox("Tsunagari - Error", str
.c_str());
108 void Log::fatal(std::string domain
, std::string msg
)
110 std::string str
= ts() + "Fatal [" + domain
+ "] - " + chomp(msg
);
111 if (inPythonScript
) {
112 PyErr_SetString(PyExc_RuntimeError
, str
.c_str());
115 std::cerr
<< str
<< std::endl
;
117 wMessageBox("Tsunagari - Fatal", str
);
120 macMessageBox("Tsunagari - Fatal", str
.c_str());
125 void Log::reportVerbosityOnStartup()
127 std::string verbString
;
128 switch (conf
.verbosity
)
131 verbString
= "QUIET";
134 verbString
= "NORMAL";
137 verbString
= "VERBOSE";
140 std::cout
<< ts() << "Reporting engine messages in " << verbString
141 << " mode." << std::endl
;
144 static void pythonLogInfo(std::string msg
)
146 Log::info("Script", msg
);
151 pythonAddFunction("log", pythonLogInfo
);