The Pedigree Project 0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Log Class Reference

the kernel's log More...

#include <Log.h>

+ Collaboration diagram for Log:

Classes

struct  CallbackPin
 
struct  CallbackSlot
 
class  LogCallback
 
struct  LogEntry
 

Public Types

enum  SeverityLevel {
  Debug = 0 , Notice , Warning , Error ,
  Fatal
}
 
typedef LogEntry StaticLogEntry
 
typedef LogEntry DynamicLogEntry
 

Public Member Functions

void initialise1 ()
 
void initialise2 ()
 
EXPORTED_PUBLIC bool installCallback (LogCallback *pCallback, bool bSkipBacklog=false)
 
EXPORTED_PUBLIC bool removeCallback (LogCallback *pCallback)
 
EXPORTED_PUBLIC void addEntry (const LogEntry &entry, bool lock=true)
 
size_t getStaticEntryCount () const
 
size_t getDynamicEntryCount () const
 
const StaticLogEntry & getStaticEntry (size_t n) const
 
const DynamicLogEntry & getDynamicEntry (size_t n) const
 
EXPORTED_PUBLIC size_t copyText (char *buffer, size_t capacity)
 
bool echoToSerial ()
 
const LogEntry & getLatestEntry () const
 
void enableTimestamps ()
 
void disableTimestamps ()
 

Static Public Member Functions

static EXPORTED_PUBLIC Log & instance ()
 
static constexpr size_t textCapacity ()
 

Public Attributes

Spinlock m_Lock
 

Private Member Functions

 Log ()
 
 ~Log ()
 
 Log (const Log &)
 
Log & operator= (const Log &)
 
const NormalStaticString & getTimestamp ()
 
const TinyStaticString & severityToString (SeverityLevel level) const
 
size_t snapshotCallbacks (CallbackPin pins[LOG_CALLBACK_COUNT])
 
bool pinCallback (CallbackSlot *slot, CallbackPin &pin)
 
bool callbackEnabled (const CallbackPin &pin)
 
void releaseCallback (CallbackPin &pin)
 
void dispatchCallbacks (CallbackPin pins[LOG_CALLBACK_COUNT], size_t count, const LogCord &message, bool locked)
 
void dispatchCallback (CallbackSlot *slot, const LogCord &message, bool locked)
 
void * currentCallbackOwner ()
 
bool isCallbackContext (void *owner)
 
void clearCallback (CallbackSlot *slot)
 

Private Attributes

StaticLogEntry m_StaticLog [LOG_ENTRIES]
 
size_t m_StaticEntries
 
size_t m_StaticEntryStart
 
size_t m_StaticEntryEnd
 
bool m_EchoToSerial
 
WaitQueue m_CallbackWaiters
 
CallbackSlot m_OutputCallbacks [LOG_CALLBACK_COUNT]
 
CallbackPin * m_ActiveCallbackPins
 
size_t m_nOutputCallbacks
 
uint64_t m_LastEntryHash
 
SeverityLevel m_LastEntrySeverity
 
size_t m_HashMatchedCount
 
bool m_Timestamps
 
Time::Timestamp m_LastTime
 
NormalStaticString m_CachedTimestamp
 

Static Private Attributes

static EXPORTED_PUBLIC Log m_Instance
 
static TinyStaticString m_DebugSeverityString
 
static TinyStaticString m_NoticeSeverityString
 
static TinyStaticString m_WarningSeverityString
 
static TinyStaticString m_ErrorSeverityString
 
static TinyStaticString m_FatalSeverityString
 
static TinyStaticString m_LineEnding
 
static NormalStaticString m_DedupeHead
 
static TinyStaticString m_DedupeTail
 

Detailed Description

the kernel's log

Implements a kernel log that can be used to debug problems.

Note
You should use the NOTICE, WARNING, ERROR and FATAL macros to write something into the log. Direct access to the log should only be needed to retrieve the entries from the log (within the debugger's log viewer for example).

Definition at line 155 of file Log.h.

Member Typedef Documentation

◆ DynamicLogEntry

Definition at line 285 of file Log.h.

◆ StaticLogEntry

Type of a static log entry (no memory-management involved)

Definition at line 284 of file Log.h.

Member Enumeration Documentation

◆ SeverityLevel

Severity level of the log entry

Definition at line 170 of file Log.h.

Constructor & Destructor Documentation

◆ Log() [1/2]

Log::Log ( )
private

Default constructor - does nothing.

Definition at line 85 of file Log.cc.

References LOG_CALLBACK_COUNT.

◆ ~Log()

Log::~Log ( )
private

Default destructor - does nothing

Definition at line 109 of file Log.cc.

References addEntry(), and NoTimestamp.

◆ Log() [2/2]

Log::Log ( const Log &  )
private

Copy-constructor

Note
NOT implemented

Member Function Documentation

◆ addEntry()

void Log::addEntry ( const LogEntry &  entry,
bool  lock = true 
)

Adds an entry to the log and immediately flushes.

Definition at line 612 of file Log.cc.

References Spinlock::acquire(), ProcessorBase::breakpoint(), EMIT_IF, Machine::getSerial(), LOG_CALLBACK_COUNT, LOG_ENTRIES, m_DedupeHead, m_HashMatchedCount, m_LastEntryHash, m_LastEntrySeverity, m_LineEnding, m_Lock, m_StaticEntries, m_StaticLog, m_Timestamps, panic(), and Spinlock::release().

Referenced by Debugger::start(), and ~Log().

+ Here is the caller graph for this function:

◆ callbackEnabled()

bool Log::callbackEnabled ( const CallbackPin &  pin)
private

Definition at line 372 of file Log.cc.

◆ clearCallback()

void Log::clearCallback ( CallbackSlot *  slot)
private

Definition at line 323 of file Log.cc.

◆ copyText()

size_t Log::copyText ( char *  buffer,
size_t  capacity 
)

Copies the newest log text without consuming entries or invoking callbacks.

Definition at line 454 of file Log.cc.

References getStaticEntry(), m_Lock, m_StaticEntries, and Log::LogEntry::str.

◆ currentCallbackOwner()

void * Log::currentCallbackOwner ( )
private

Definition at line 300 of file Log.cc.

◆ disableTimestamps()

void Log::disableTimestamps ( )

Definition at line 744 of file Log.cc.

◆ dispatchCallback()

void Log::dispatchCallback ( CallbackSlot *  slot,
const LogCord &  message,
bool  locked 
)
private

Definition at line 422 of file Log.cc.

◆ dispatchCallbacks()

void Log::dispatchCallbacks ( CallbackPin  pins[LOG_CALLBACK_COUNT],
size_t  count,
const LogCord &  message,
bool  locked 
)
private

Definition at line 405 of file Log.cc.

◆ echoToSerial()

bool Log::echoToSerial ( )

Definition at line 486 of file Log.cc.

◆ enableTimestamps()

void Log::enableTimestamps ( )

Definition at line 739 of file Log.cc.

◆ getDynamicEntry()

const Log::DynamicLogEntry & Log::getDynamicEntry ( size_t  n) const

Returns the (n - getStaticEntryCount())'th dynamic log entry

Definition at line 450 of file Log.cc.

References m_StaticLog.

◆ getDynamicEntryCount()

size_t Log::getDynamicEntryCount ( ) const

Get the number of dynamic entries in the log

Returns
the number of dynamic entries in the log

Definition at line 442 of file Log.cc.

◆ getLatestEntry()

const Log::LogEntry & Log::getLatestEntry ( ) const

Definition at line 490 of file Log.cc.

◆ getStaticEntry()

const Log::StaticLogEntry & Log::getStaticEntry ( size_t  n) const

Returns the n'th static log entry, counting from the start.

Definition at line 446 of file Log.cc.

References LOG_ENTRIES, and m_StaticLog.

Referenced by copyText().

+ Here is the caller graph for this function:

◆ getStaticEntryCount()

size_t Log::getStaticEntryCount ( ) const

Get the number of static entries in the log.

Returns
the number of static entries in the log

Definition at line 438 of file Log.cc.

References m_StaticEntries.

◆ getTimestamp()

const NormalStaticString & Log::getTimestamp ( )
private

Definition at line 759 of file Log.cc.

◆ initialise1()

void Log::initialise1 ( )

Initialises the Log

Definition at line 121 of file Log.cc.

References m_EchoToSerial.

◆ initialise2()

void Log::initialise2 ( )

Initialises the default Log callback (to a serial port)

Definition at line 138 of file Log.cc.

References EMIT_IF, and m_EchoToSerial.

◆ installCallback()

bool Log::installCallback ( LogCallback *  pCallback,
bool  bSkipBacklog = false 
)

Installs an output callback.

A callback may only be registered once. Returns false for a null, duplicate, or full registration.

Note
This could send a massive batch of log entries on the callback. If the callback isn't designed to handle big buffers this may fail.

Definition at line 145 of file Log.cc.

References Log::LogEntry::lockfree, LOG_CALLBACK_COUNT, LOG_ENTRIES, m_CallbackWaiters, m_LineEnding, m_Lock, m_StaticEntries, m_StaticLog, m_Timestamps, Log::LogEntry::severity, and Log::LogEntry::str.

◆ instance()

Log & Log::instance ( )
static

Retrieves the static Log instance.

Returns
instance of the log class

Definition at line 117 of file Log.cc.

References m_Instance.

Referenced by Debugger::start().

+ Here is the caller graph for this function:

◆ isCallbackContext()

bool Log::isCallbackContext ( void *  owner)
private

Definition at line 314 of file Log.cc.

◆ operator=()

Log & Log::operator= ( const Log &  )
private

Assignment operator

Note
NOT implemented

◆ pinCallback()

bool Log::pinCallback ( CallbackSlot *  slot,
CallbackPin &  pin 
)
private

Definition at line 356 of file Log.cc.

◆ releaseCallback()

void Log::releaseCallback ( CallbackPin &  pin)
private

Definition at line 377 of file Log.cc.

◆ removeCallback()

bool Log::removeCallback ( LogCallback *  pCallback)

Closes a callback registration and drains committed invocations.

Returns true once no invocation can still use the callback. A live target cannot be drained from callback context, so admission is closed and false retains the registration for a later external retry. An idle target may be removed immediately from any context.

Definition at line 228 of file Log.cc.

References ProcessorBase::getInterrupts(), ProcessorBase::information(), LOG_CALLBACK_COUNT, and m_CallbackWaiters.

◆ severityToString()

const TinyStaticString & Log::severityToString ( SeverityLevel  level) const
private

Definition at line 786 of file Log.cc.

◆ snapshotCallbacks()

size_t Log::snapshotCallbacks ( CallbackPin  pins[LOG_CALLBACK_COUNT])
private

Definition at line 330 of file Log.cc.

◆ textCapacity()

static constexpr size_t Log::textCapacity ( )
inlinestaticconstexpr

Definition at line 295 of file Log.h.

Member Data Documentation

◆ m_ActiveCallbackPins

CallbackPin* Log::m_ActiveCallbackPins
private

Definition at line 370 of file Log.h.

◆ m_CachedTimestamp

NormalStaticString Log::m_CachedTimestamp
private

Cached timestamp string.

Definition at line 392 of file Log.h.

◆ m_CallbackWaiters

WaitQueue Log::m_CallbackWaiters
private

Callback registrations and their committed invocation pins.

Definition at line 368 of file Log.h.

Referenced by installCallback(), and removeCallback().

◆ m_DebugSeverityString

TinyStaticString Log::m_DebugSeverityString
staticprivate

Log severity tag strings.

Definition at line 395 of file Log.h.

◆ m_DedupeHead

NormalStaticString Log::m_DedupeHead
staticprivate

Dedupe information strings.

Definition at line 405 of file Log.h.

Referenced by addEntry().

◆ m_DedupeTail

TinyStaticString Log::m_DedupeTail
staticprivate

Definition at line 406 of file Log.h.

◆ m_EchoToSerial

bool Log::m_EchoToSerial
private

If we should output to serial

Definition at line 365 of file Log.h.

Referenced by initialise1(), and initialise2().

◆ m_ErrorSeverityString

TinyStaticString Log::m_ErrorSeverityString
staticprivate

Definition at line 398 of file Log.h.

◆ m_FatalSeverityString

TinyStaticString Log::m_FatalSeverityString
staticprivate

Definition at line 399 of file Log.h.

◆ m_HashMatchedCount

size_t Log::m_HashMatchedCount
private

Number of entries that matched the last entry hash.

Definition at line 383 of file Log.h.

Referenced by addEntry().

◆ m_Instance

Log Log::m_Instance
staticprivate

The Log instance (singleton class)

Definition at line 374 of file Log.h.

Referenced by instance().

◆ m_LastEntryHash

uint64_t Log::m_LastEntryHash
private

Last seen message hash (for cleaning up dupes).

Definition at line 377 of file Log.h.

Referenced by addEntry().

◆ m_LastEntrySeverity

SeverityLevel Log::m_LastEntrySeverity
private

Last seen message severity (for cleaning up dupes).

Definition at line 380 of file Log.h.

Referenced by addEntry().

◆ m_LastTime

Time::Timestamp Log::m_LastTime
private

Last timestamp seen in getTimestamp().

Definition at line 389 of file Log.h.

◆ m_LineEnding

TinyStaticString Log::m_LineEnding
staticprivate

Log line ending string.

Definition at line 402 of file Log.h.

Referenced by addEntry(), and installCallback().

◆ m_Lock

Spinlock Log::m_Lock

The lock

Note
this should only be acquired by the NOTICE, WARNING, ERROR and FATAL macros

Definition at line 175 of file Log.h.

Referenced by addEntry(), copyText(), and installCallback().

◆ m_NoticeSeverityString

TinyStaticString Log::m_NoticeSeverityString
staticprivate

Definition at line 396 of file Log.h.

◆ m_nOutputCallbacks

size_t Log::m_nOutputCallbacks
private

Definition at line 371 of file Log.h.

◆ m_OutputCallbacks

CallbackSlot Log::m_OutputCallbacks[LOG_CALLBACK_COUNT]
private

Definition at line 369 of file Log.h.

◆ m_StaticEntries

size_t Log::m_StaticEntries
private

Dynamic buffer of log messages Number of entries in the static log

Definition at line 360 of file Log.h.

Referenced by addEntry(), copyText(), getStaticEntryCount(), and installCallback().

◆ m_StaticEntryEnd

size_t Log::m_StaticEntryEnd
private

Definition at line 362 of file Log.h.

◆ m_StaticEntryStart

size_t Log::m_StaticEntryStart
private

Definition at line 362 of file Log.h.

◆ m_StaticLog

StaticLogEntry Log::m_StaticLog[LOG_ENTRIES]
private

Static buffer of log messages.

Definition at line 356 of file Log.h.

Referenced by addEntry(), getDynamicEntry(), getStaticEntry(), and installCallback().

◆ m_Timestamps

bool Log::m_Timestamps
private

Are timestamps enabled?

Definition at line 386 of file Log.h.

Referenced by addEntry(), and installCallback().

◆ m_WarningSeverityString

TinyStaticString Log::m_WarningSeverityString
staticprivate

Definition at line 397 of file Log.h.


The documentation for this class was generated from the following files: