ConsoleLog::ConsoleLog(bool dateStamping, bool timeStamping, bool showCat, bool showLevel) { timeStamping_ = timeStamping; dateStamping_ = dateStamping; showCat_ = showCat; showLevel_ = showLevel; std::cout << getLevelColor(Info); #ifdef __unix__ colorOutput_ = true; #else colorOutput_ = false; #endif }
void HtmlLog::logFiltered(const std::string &cat, LogLevel level, const std::string &msg, const std::string &extendedInfo) { if (!file_) return; std::string output = "\t\t\t<tr bgcolor=\"" + getLevelColor(level) + "\">\n"; if (dateStamping_) output += "\t\t\t\t<td>" + getDateString() + "</td>\n"; if (timeStamping_) output += "\t\t\t\t<td>" + getTimeString() + "</td>\n"; if (showCat_) output += "\t\t\t\t<td>" + cat + "</td>\n"; if (showLevel_) output += "\t\t\t\t" + getLevelString(level) + "\n"; fputs((output + "\t\t\t\t<td title=\"" + extendedInfo + "\">" + msg + "</td>\n\t\t\t</tr>\n").c_str(), file_); fflush(file_); }
void ConsoleLog::logFiltered(const std::string& cat, LogLevel level, const std::string& msg, const std::string& /*extendedInfo*/) { std::string output; if (colorOutput_) output = getLevelColor(level); if (dateStamping_) output += "[" + getDateString() + "] "; if (timeStamping_) output += "[" + getTimeString() + "] "; if (showCat_) output += cat + " "; if (showLevel_) output += "(" + getLevelString(level) + ") "; if (output != "") output += '\t'; output += msg; if (colorOutput_) output += "\033[00m"; // return to default color (Reset all attributes) std::cout << output << std::endl; }
static void logVPrintf (const LogContext* context, const char* errorStr, const char* format, va_list formatArgs) { char buffer[2048] = ""; int count = vsnprintf (buffer, sizeof (buffer), format, formatArgs); if (count >= (int) sizeof (buffer)) fprintf (stderr, "Error: log entry is too long for format string [%s]\n", format); const char* file = ""; char line[18] = ""; if (pixi_logFileContext && context->file) { file = context->file; snprintf (line, sizeof (line), ":%d: ", context->line); } const char* prog = program_invocation_short_name; const char* lev = pixi_logLevelToStr (context->level); const char* startColor = getLevelColor (context->level); const char* endColor = ""; if (startColor) endColor = levelColors[LogLevelOff]; else startColor = ""; const char* errorColon = ""; if (errorStr) errorColon = ": "; else errorStr = ""; fprintf (stderr, "%s%s%s%s: %s: %s%s%s%s\n", file, line, startColor, prog, lev, buffer, errorColon, errorStr, endColor ); if (logFile) { if (logSize > maxLogSize) rotateLogFile(); char timeStr[40] = ""; pixi_formatCurTime (timeStr, sizeof (timeStr)); int written = fprintf (logFile, "%s %s%s%s: %s%s%s\n", timeStr, file, line, lev, buffer, errorColon, errorStr ); if (written < 0) perror ("Error writing to log file"); else { fflush (logFile); logSize += written; } } }