CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/Log/StdioListener.cpp
Views: 1401
// Copyright (C) 2014- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official SVN repository and contact information can be found at15// http://code.google.com/p/dolphin-emu/1617#include <atomic>18#include <algorithm> // min19#include <cstring>20#include <string> // System: To be able to add strings with "+"21#include <math.h>22#include <stdarg.h>23#ifndef _MSC_VER24#include <unistd.h>25#endif2627#include "ppsspp_config.h"28#include "Common/Thread/ThreadUtil.h"29#include "Common/Data/Encoding/Utf8.h"30#include "Common/CommonTypes.h"31#include "Common/Log/StdioListener.h"32#include "Common/StringUtils.h"3334StdioListener::StdioListener() {35#if PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(UWP) || PPSSPP_PLATFORM(SWITCH)36bUseColor = false;37#elif defined(_MSC_VER)38bUseColor = false;39#elif defined(__APPLE__)40// Xcode builtin terminal used for debugging does not support colours.41// Fortunately it can be detected with a TERM env variable.42bUseColor = isatty(fileno(stdout)) && getenv("TERM") != NULL;43#else44bUseColor = isatty(fileno(stdout));45#endif46}4748void StdioListener::Log(const LogMessage &msg) {49char Text[2048];50snprintf(Text, sizeof(Text), "%s %s %s", msg.timestamp, msg.header, msg.msg.c_str());51Text[sizeof(Text) - 2] = '\n';52Text[sizeof(Text) - 1] = '\0';5354char ColorAttr[16] = "";55char ResetAttr[16] = "";5657if (bUseColor) {58strcpy(ResetAttr, "\033[0m");59switch (msg.level) {60case LogLevel::LNOTICE: // light green61strcpy(ColorAttr, "\033[92m");62break;63case LogLevel::LERROR: // light red64strcpy(ColorAttr, "\033[91m");65break;66case LogLevel::LWARNING: // light yellow67strcpy(ColorAttr, "\033[93m");68break;69case LogLevel::LINFO: // cyan70strcpy(ColorAttr, "\033[96m");71break;72case LogLevel::LDEBUG: // gray73strcpy(ColorAttr, "\033[90m");74break;75default:76break;77}78}79fprintf(stderr, "%s%s%s", ColorAttr, Text, ResetAttr);80}818283