20 #include "pedigree/kernel/Log.h" 21 #include "pedigree/kernel/BootstrapInfo.h" 22 #include "pedigree/kernel/LockGuard.h" 23 #include "pedigree/kernel/machine/Machine.h" 24 #include "pedigree/kernel/machine/Timer.h" 25 #include "pedigree/kernel/panic.h" 26 #include "pedigree/kernel/processor/Processor.h" 27 #include "pedigree/kernel/process/Scheduler.h" 28 #include "pedigree/kernel/time/Time.h" 29 #include "pedigree/kernel/utilities/StaticCord.h" 30 #include "pedigree/kernel/utilities/String.h" 31 #include "pedigree/kernel/utilities/StringView.h" 32 #include "pedigree/kernel/utilities/Vector.h" 33 #include "pedigree/kernel/utilities/utility.h" 38 #define LOG_MAX_DEDUPE_MESSAGES 20 41 #define LOG_TIMESTAMPS_IN_NANOS 0 54 #ifndef SERIAL_IS_FILE 64 static const char *g_RepeatedStrings[] = {
65 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
66 "10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
69 static size_t g_RepeatedLengths[] = {
70 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
71 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
74 static const size_t g_NumRepeatedStrings = 20;
81 m_StaticEntries(0), m_StaticEntryStart(0), m_StaticEntryEnd(0),
83 #ifdef DONT_LOG_TO_SERIAL
84 m_EchoToSerial(false),
88 m_nOutputCallbacks(0),
90 m_LastEntrySeverity(Fatal),
91 m_HashMatchedCount(0),
104 entry << Notice <<
"-- Log Terminating --";
116 char *cmdline = g_pBootstrapInfo->getCommandLine();
120 for (
auto it = cmds.
begin(); it != cmds.
end(); it++)
123 if (
cmd ==
String(
"--disable-log-to-serial"))
128 else if (
cmd ==
String(
"--enable-log-to-serial"))
140 #ifndef DONT_LOG_TO_SERIAL 142 installSerialLogger();
158 ++m_nOutputCallbacks;
176 size_t entry = m_StaticEntryStart;
182 if (entry == m_StaticEntryEnd)
188 msg.append(
"(backlog) ", 10);
191 msg.append(severity, severity.length());
195 msg.append(ts, ts.length());
203 pCallback->callback(msg);
219 --m_nOutputCallbacks;
245 bool Log::echoToSerial()
268 str.appendBytes(s, s.length());
274 str.appendBytes(s.str(), s.length());
280 return (*
this) << (
reinterpret_cast<const char *
>(append_str));
286 return *
this <<
"true";
288 return *
this <<
"false";
305 str.append(n, radix);
321 #ifndef UTILITY_LINUX 322 Machine &machine = Machine::instance();
323 if (machine.isInitialised() ==
true && machine.
getTimer() != 0)
380 static bool handlingFatal =
false;
392 m_StaticEntryStart = (m_StaticEntryStart + 1) %
LOG_ENTRIES;
398 m_StaticEntryEnd = (m_StaticEntryEnd + 1) %
LOG_ENTRIES;
407 if (m_nOutputCallbacks)
409 bool wasRepeated =
false;
410 uint64_t repeatedTimes = 0;
449 if (repeatedTimes < g_NumRepeatedStrings)
451 msg.append(g_RepeatedStrings[repeatedTimes], g_RepeatedLengths[repeatedTimes]);
456 repeated.append(repeatedTimes);
457 msg.append(repeated, repeated.length());
459 msg.append(m_DedupeTail, m_DedupeTail.length());
464 msg.append(severity, severity.length());
468 msg.append(ts, ts.length());
485 handlingFatal =
true;
487 const char *panicstr =
static_cast<const char *
>(
m_Buffer.
str);
497 void Log::enableTimestamps()
502 void Log::disableTimestamps()
509 Time::Timestamp tn = Time::getTimeNanoseconds();
510 Time::Timestamp ts = Time::getTime();
512 #if LOG_TIMESTAMPS_IN_NANOS 542 return m_NoticeSeverityString;
544 return m_WarningSeverityString;
546 return m_ErrorSeverityString;
548 return m_FatalSeverityString;
552 Log::LogCallback::~LogCallback() =
default;
Bootstrap structure passed to the kernel entry point.
size_t m_HashMatchedCount
EXPORTED_PUBLIC void addEntry(const LogEntry &entry, bool lock=true, bool flush=true)
StaticString< LOG_LENGTH > str
Time::Timestamp m_LastTime
A vector / dynamic array.
virtual Timer * getTimer()=0
static TinyStaticString m_LineEnding
size_t getStaticEntryCount() const
bool acquire(bool recurse=false, bool safe=true)
const StaticLogEntry & getStaticEntry(size_t n) const
StaticLogEntry m_StaticLog[LOG_ENTRIES]
void allowHashing(bool computeNow=false)
SeverityLevel m_LastEntrySeverity
const DynamicLogEntry & getDynamicEntry(size_t n) const
EXPORTED_PUBLIC Log & operator<<(const LogEntry &entry)
virtual uint64_t getTickCount()=0
EXPORTED_PUBLIC void removeCallback(LogCallback *pCallback)
size_t getDynamicEntryCount() const
static EXPORTED_PUBLIC Log m_Instance
LogCallback * m_OutputCallbacks[LOG_CALLBACK_COUNT]
static EXPORTED_PUBLIC Log & instance()
LogEntry & operator<<(const char *)
void EXPORTED_PUBLIC panic(const char *msg) NORETURN
void flushEntry(bool lock=true)
#define LOG_CALLBACK_COUNT
static TinyStaticString m_DebugSeverityString
EXPORTED_PUBLIC void installCallback(LogCallback *pCallback, bool bSkipBacklog=false)
static NormalStaticString m_DedupeHead
NormalStaticString m_CachedTimestamp