blob: b510ba357ce3f3173c9749c627071dc78b4d4b2c [file] [log] [blame]
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "DebugLogger.h"
#include <stdio.h>
// *************************************************************************************************
LogConfig g_LogConfig(LOG_SEV_INFO, false);
// *************************************************************************************************
LogConfig::LogConfig(LogSeverity maxSeverity, bool bPrintLocation)
: m_MaxSeverity(maxSeverity)
, m_ShowStatusBar(false)
, m_PrintLocation(bPrintLocation)
, m_ExitOnAssert(false)
{
}
void LogConfig::SetStatusBarPrinter(bool statusBarShow)
{
m_ShowStatusBar = statusBarShow;
std::cout << "m_ShowStatusBar is " << m_ShowStatusBar << std::endl;
}
void LogConfig::SetMaxSeverity(int traceLevel)
{
if (traceLevel > LOG_SEV_VERBOSE)
{
fprintf(stderr, "Invalid trace level, setting %d\n", LOG_SEV_VERBOSE);
m_MaxSeverity = LOG_SEV_VERBOSE;
}
else
{
m_MaxSeverity = static_cast<LogSeverity>(traceLevel);
fprintf(stdout, "Setting trace level to %d\n", m_MaxSeverity);
}
}
// *************************************************************************************************
const char* LogMsgPrefix::SeverityToString(LogSeverity sev)
{
static const char* const pSeverityToString[] = { "ERR", "WRN", "INF", "DBG", "VRB" };
size_t index = static_cast<size_t>(sev);
if (index >= sizeof(pSeverityToString) / sizeof(pSeverityToString[0]))
{
return "---";
}
return pSeverityToString[index];
}
std::ostream& operator<<(std::ostream& os, const LogMsgPrefix& prefix)
{
os << '[' << LogMsgPrefix::SeverityToString(prefix.Severity) << "] ";
if (!g_LogConfig.ShouldPrintLocation()) return os;
return os << "(" << prefix.File << ':' << prefix.Line << ") ";
}