ofs | hex dump | ascii |
---|
0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 00 00 00 01 00 08 06 00 00 00 5c 72 a8 | .PNG........IHDR.............\r. |
0020 | 66 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 0e c3 00 | f....bKGD..............pHYs..... |
0040 | 00 0e c3 01 c7 6f a8 64 00 00 00 07 74 49 4d 45 07 e0 06 09 13 13 34 76 e3 a3 06 00 00 20 00 49 | .....o.d....tIME......4v.......I |
0060 | 44 41 54 78 da ec bd 69 94 5d e7 59 26 fa 7c d3 9e ce 50 55 a7 06 cd 52 55 69 b4 64 c9 83 64 9b | DATx...i.].Y&.|...PU...RUi.d..d. |
0080 | 28 b6 93 38 b1 89 21 40 47 31 61 c8 8d 3b ac 40 e8 0b 84 6e ba ef 5d b9 eb 76 37 69 58 ac 06 3a | (..8..!@G1a..;.@...n..]..v7iX..: |
00a0 | ac 6e 20 74 26 9a d0 04 72 49 c7 40 80 0c 24 74 4c 70 70 06 0f b2 3c c4 92 27 a9 4a b6 64 4b aa | .n.t&...rI.@..$tLpp...<..'.J.dK. |
00c0 | e1 9c aa 3a 67 9f bd f7 37 dd 1f fb 7c bb 4e 95 25 8f 72 82 9d fd 7a 9d 55 52 e9 c8 a5 b3 f7 7e | ...:g...7...|.N.%.r...z.UR.....~ |
00e0 | de ef 1d 9e f7 79 81 d2 4a 2b ad b4 d2 4a 2b ad b4 d2 4a 2b ad b4 d2 4a 2b ad b4 d2 4a 2b ad b4 | .....y..J+...J+...J+...J+...J+.. |
0100 | d2 4a 2b ad b4 d2 4a 2b ad b4 d2 4a 2b ad b4 d2 4a 2b ad b4 d2 4a 2b ad b4 d2 4a 2b ad b4 d2 4a | .J+...J+...J+...J+...J+...J+...J |
0120 | 2b ad b4 d2 5e 8b 46 ae be fa 6a 5e 5e 86 d7 d8 4d 2d 2f 41 69 2f c0 d8 35 d7 5c 3e e9 79 d1 a5 | +...^.F...j^^...M-/Ai/..5.\>.y.. |
0140 | 46 9a 6f 49 63 e6 00 d0 bb ef be 3b 2d 2f cd ab fc c6 96 97 a0 b4 e7 7b 46 ae be fc f2 9d dc 0f | F.oIc......;-/.........{F....... |
0160 | 7e c2 5a fc 58 26 b3 ab bb ed ce 91 28 0c 3b 63 f5 3a 7f 66 66 46 97 97 a8 74 00 a5 bd 46 9f 8f | ~.Z.X&......(.;c.:.ffF...t...F.. |
0180 | bd 7b 77 6e f3 7c ef 1d 20 f8 f1 2c 53 7b b2 2c 1b a3 8c 6f 27 94 de d5 4d d3 85 91 d1 51 6f 76 | .{wn.|.....,S{.,...o'...M....Qov |
01a0 | 76 b6 74 02 a5 03 28 ed b5 f6 6c ec dc b9 73 9b e7 89 43 20 e4 1d 4a 99 5d 52 ea 0a a5 2c ac 54 | v.t...(...l...s...C...J.]R...,.T |
01c0 | 2a 83 61 18 ee 18 1e 19 b9 c7 18 d3 de bc 79 73 78 ea d4 29 05 c0 96 97 ad 74 00 a5 bd 16 c0 3f | *.a...........ysx..).....t.....? |
01e0 | 3e be 4d 84 fe 21 4a c8 2d c6 d8 dd c6 20 e0 5c 90 28 8a 58 18 86 61 14 45 83 8d 46 63 fb e6 cd | >.M..!J.-......\.(.X..a.E..Fc... |
0200 | 9b 0f 67 59 46 f6 ed db 17 1d 3b 76 ac 5b 3a 81 d2 01 94 f6 2a 7f 26 c6 c7 c7 b7 89 40 1c 22 84 | ..gYF.....;v.[:.....*.&.....@.". |
0220 | de 42 40 76 13 c2 02 21 3c 84 61 88 28 8a 48 14 45 6c 70 70 30 1c 1e 1e 1e ac d5 6a db 82 20 98 | .B@v...!<.a.(.H.Elpp0......j.... |
0240 | 1e 18 18 d8 70 dd 75 d7 c9 6f 7d eb 5b 4b a5 13 28 1d 40 69 af 66 f0 33 76 88 10 72 0b 65 6c 37 | ....p.u..o}.[K..(.@i.f.3v..r.el7 |
0260 | a5 3c f0 3c 0f 41 10 20 08 02 44 51 84 c1 c1 41 d2 68 34 58 a5 52 09 39 e7 83 94 d2 4b 7c df 6f | .<.<.A....DQ...A.h4X.R.9....K|.o |
0280 | f8 be ef 5f 75 d5 55 ad d2 09 94 0e a0 b4 ef a1 7d f0 83 a0 63 33 bb f9 b5 9b 37 d3 c3 cf 3c 63 | ..._u.U.........}...c3....7...<c |
02a0 | 5f 0c f8 03 c1 0e 81 d2 5b 28 a5 bb 39 17 81 ef fb 70 af 30 0c 31 30 30 80 46 a3 81 5a ad 46 18 | _.......[(..9....p.0.100.F..Z.F. |
02c0 | 63 4c 4a 19 02 18 e5 9c ef 55 4a 55 b2 2c 4b f6 ec d9 d3 3c 72 e4 48 e9 04 4a 07 50 da 77 db de | cLJ......UJU.,K....<r.H..J.P.w.. |
02e0 | ff fe b7 7a 03 c9 81 ca da c9 4d 21 5b 17 d1 75 13 03 ea e8 d1 53 cf fb 1c ec dd b9 73 5b 10 fa | ...z......M![..u.....S......s[.. |
0300 | 87 2c 21 b7 10 42 76 73 ce 03 df f7 11 04 01 dc 57 07 fe 4a a5 02 ce 39 a4 94 44 4a c9 38 e7 a1 | .,!..Bvs........W..J...9..DJ.8.. |
0320 | b5 36 ca b2 6c 93 94 d2 67 8c 75 f7 ed db 57 3a 81 d2 01 94 f6 dd b4 2f fe cf df 20 dd b6 f5 0d | .6..l...g.u...W:......./........ |
0340 | e5 be a1 88 95 d6 29 97 b0 e3 eb 07 71 f4 f8 33 17 06 ff de bd db 44 e0 1d 02 ec 2d c6 60 37 a5 | ......).....q..3......D....-.`7. |
0360 | 34 f0 fc 00 41 18 22 e8 03 ff e0 e0 20 aa d5 2a 38 e7 50 4a 21 4d 53 50 4a 09 a5 94 a6 69 4a a5 | 4...A."........*8.PJ!MSPJ....iJ. |
0380 | 94 9e 31 66 23 21 a4 74 02 af 12 2b 99 80 af 11 bb ed 77 7f 89 3c 3c 35 1f 5a 02 0a 8b 6e dc 8d | ..1f#!.t...+......w..<<5.Z...n.. |
03a0 | cd 87 3e f1 d7 05 f0 5e 7f f9 46 f2 8d /*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <map>
#include <queue>
#include <string>
#include <fstream>
#include <thread>
#include <mutex>
#if !defined(_WIN32) // POSIX
#include <unistd.h>
#endif
#include "irrlichttypes.h"
class ILogOutput;
enum LogLevel {
LL_NONE, // Special level that is always printed
LL_ERROR,
LL_WARNING,
LL_ACTION, // In-game actions
LL_INFO,
LL_VERBOSE,
LL_MAX,
};
enum LogColor {
LOG_COLOR_NEVER,
LOG_COLOR_ALWAYS,
LOG_COLOR_AUTO,
};
typedef u8 LogLevelMask;
#define LOGLEVEL_TO_MASKLEVEL(x) (1 << x)
class Logger {
public:
void addOutput(ILogOutput *out);
void addOutput(ILogOutput *out, LogLevel lev);
void addOutputMasked(ILogOutput *out, LogLevelMask mask);
void addOutputMaxLevel(ILogOutput *out, LogLevel lev);
LogLevelMask removeOutput(ILogOutput *out);
void setLevelSilenced(LogLevel lev, bool silenced);
void registerThread(const std::string &name);
void deregisterThread();
void log(LogLevel lev, const std::string &text);
// Logs without a prefix
void logRaw(LogLevel lev, const std::string &text);
void setTraceEnabled(bool enable) { m_trace_enabled = enable; }
bool getTraceEnabled() { return m_trace_enabled; }
static LogLevel stringToLevel(const std::string &name);
static const std::string getLevelLabel(LogLevel lev);
static LogColor color_mode;
private:
void logToOutputsRaw(LogLevel, const std::string &line);
void logToOutputs(LogLevel, const std::string &combined,
const std::string &time, const std::string &thread_name,
const std::string &payload_text);
const std::string getThreadName();
std::vector<ILogOutput *> m_outputs[LL_MAX];
// Should implement atomic loads and stores (even though it's only
// written to when one thread has access currently).
// Works on all known architectures (x86, ARM, MIPS).
volatile bool m_silenced_levels[LL_MAX];
std::map<std::thread::id, std::string> m_thread_names;
mutable std::mutex m_mutex;
bool m_trace_enabled;
};
class ILogOutput {
public:
virtual void logRaw(LogLevel, const std::string &line) = 0;
virtual void log(LogLevel, const std::string &combined,
const std::string &time, const std::string &thread_name,
const std::string &payload_text) = 0;
};
class ICombinedLogOutput : public ILogOutput {
public:
void log(LogLevel lev, const std::string &combined,
const std::string &time, const std::string &thread_name,
const std::string &payload_text)
{
logRaw(lev, combined);
}
};
class StreamLogOutput : public ICombinedLogOutput {
public:
StreamLogOutput(std::ostream &stream) :
m_stream(stream)
{
#if !defined(_WIN32)
is_tty = isatty(fileno(stdout));
#else
is_tty = false;
#endif
}
void logRaw(LogLevel lev, const std::string &line);
private:
std::ostream &m_stream;
bool is_tty;
};
class FileLogOutput : public ICombinedLogOutput {
public:
void setFile(const std::string &filename, s64 file_size_max);
void logRaw(LogLevel lev, const std::string &line)
{
m_stream << line << std::endl;
}
private:
std::ofstream m_stream;
};
class LogOutputBuffer : public ICombinedLogOutput {
public:
LogOutputBuffer(Logger &logger) :
m_logger(logger)
{
updateLogLevel();
};
virtual ~LogOutputBuffer()
{
m_logger.removeOutput(this);
}
void updateLogLevel();
void logRaw(LogLevel lev, const std::string &line);
void clear()
{
m_buffer = std::queue<std::string>();
}
bool empty() const
{
return m_buffer.empty();
}
std::string get()
{
if (empty())
return "";
std::string s = m_buffer.front();
m_buffer.pop();
return s;
}
private:
std::queue<std::string> m_buffer;
Logger &m_logger;
};
extern StreamLogOutput stdout_output;
extern StreamLogOutput stderr_output;
extern std::ostream null_stream;
extern std::ostream *dout_con_ptr;
extern std::ostream *derr_con_ptr;
extern std::ostream *derr_server_ptr;
extern Logger g_logger;
// Writes directly to all LL_NONE log outputs for g_logger with no prefix.
extern std::ostream rawstream;
extern std::ostream errorstream;
extern std::ostream warningstream;
extern std::ostream actionstream;
extern std::ostream infostream;
extern std::ostream verbosestream;
extern std::ostream dstream;
#define TRACEDO(x) do { \
if (g_logger.getTraceEnabled()) { \
x; \
} \
} while (0)
#define TRACESTREAM(x) TRACEDO(verbosestream x)
#define dout_con (*dout_con_ptr)
#define derr_con (*derr_con_ptr)
|