Ejemplo n.º 1
0
// Output the Log to the Visual Studio debugger using OutputDebugString()
void OutputDebug::output(const Channel::Ptr& aChannelPtr, const Log& aLog) const {
    const DateTime&     time = aLog.getTime();
    char                buffer[256];

    // uses snprintf for atomic thread-safe operation
    _snprintf(buffer, sizeof(buffer), "%.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.3u  %-12s %s %s\n",
            time.year, time.month, time.day,
            time.hour, time.minute, time.second, time.ms,
            aChannelPtr->getName().c_str(), Log::toString(aLog.getSeverity()), (aLog.getStream()).str().c_str());
    buffer[255] = '\0';
    OutputDebugStringA(buffer);
}
Ejemplo n.º 2
0
		// Output the Log to the standard console using fprintf
		void OutputConsole::output(const Channel::Ptr& aChannelPtr, const Log& aLog) const {
			const DateTime& time = aLog.getTime();

			// uses fprintf for atomic thread-safe operation
#ifdef _WIN32
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), toWin32Attribute(aLog.getSeverity()));
			fprintf(stdout, "%.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.3u  %-12s %s %s\n",
#else  // _WIN32
					fprintf(stdout, "\x1B[%02um%.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.3u  %-12s %s %s\x1b[39m\n",
							toEscapeCode(aLog.getSeverity()),
#endif // _WIN32
							time.year, time.month, time.day,
							time.hour, time.minute, time.second, time.ms,
							aChannelPtr->getName().c_str(), Log::toString(aLog.getSeverity()), (aLog.getStream()).str().c_str());
#ifdef _WIN32
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
#endif // _WIN32
			fflush(stdout);
		}
Ejemplo n.º 3
0
// Output the Log to the standard console using printf
void OutputFile::output(const Channel::Ptr& aChannelPtr, const Log& aLog) const {
    const DateTime& time = aLog.getTime();

    if (mSize > mMaxSize) {
        rotate();
    }

    if (nullptr != mpFile) {
        // uses fprintf for atomic thread-safe operation
        int nbWritten = fprintf(mpFile, "%.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.3u  %-12s %s %s\n",
                                time.year, time.month, time.day,
                                time.hour, time.minute, time.second, time.ms,
                                aChannelPtr->getName().c_str(), Log::toString(aLog.getSeverity()),
                                (aLog.getStream()).str().c_str());
        fflush(stdout);

        mSize += nbWritten;
    }
}