Skip to content

Commit

Permalink
fwrite instead of fprintf.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Apr 19, 2015
1 parent 0b5a1da commit a24b75a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions rct/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ static std::mutex sOutputsMutex;
static int sLevel = 0;
static const bool sTimedLogs = getenv("RCT_LOG_TIME");

static inline void writeLog(FILE *f, const char *msg, int len)
{
if (sTimedLogs) {
const String time = String::formatTime(::time(0), String::Time);
fwrite(time.constData(), time.size(), 1, f);
}
fwrite(msg, len, 1, f);
fwrite("\n", 1, 1, f);
}
class FileOutput : public LogOutput
{
public:
Expand All @@ -29,12 +38,7 @@ class FileOutput : public LogOutput

virtual void log(const char *msg, int len) override
{
if (sTimedLogs) {
const String time = String::formatTime(::time(0), String::Time);
fwrite(time.constData(), time.size(), 1, file);
}
fwrite(msg, len, 1, file);
fwrite("\n", 1, 1, file);
writeLog(file, msg, len);
fflush(file);
}
FILE *file;
Expand All @@ -46,13 +50,9 @@ class StderrOutput : public LogOutput
StderrOutput(int lvl)
: LogOutput(lvl)
{}
virtual void log(const char *msg, int) override
virtual void log(const char *msg, int len) override
{
if (sTimedLogs) {
fprintf(stderr, "%s %s\n", String::formatTime(time(0), String::Time).constData(), msg);
} else {
fprintf(stderr, "%s\n", msg);
}
writeLog(stderr, msg, len);
}
};

Expand Down

0 comments on commit a24b75a

Please sign in to comment.