MtnLog  2.7.2
Moltony's Logging Library
mtnlog.h File Reference
#include <stdbool.h>
#include <stdarg.h>

Go to the source code of this file.

Macros

#define MTNLOG_BOOL   bool
 MtnLog boolean type. More...
 
#define mtnlogMessageC(level, ...)   mtnlogMessageCInternal(__LINE__, __FILE__, "", (level), __VA_ARGS__)
 Log message with context. More...
 
#define mtnlogMessageTagC(level, tag, ...)   mtnlogMessageTagCInternal(__LINE__, __FILE__, "", (level), (tag), __VA_ARGS__)
 Log message with tag and context. More...
 

Typedefs

typedef void(* MtnLogCallback) (MtnLogLevel, const char *, const char *)
 Log callback function. More...
 

Enumerations

enum  MtnLogLevel { MTNLOG_INFO = 0 , MTNLOG_WARNING = 1 , MTNLOG_ERROR = 2 }
 Enum representing logging level. More...
 

Functions

void mtnlogInit (const MtnLogLevel level, const char *logFileName)
 Initialize logging. More...
 
void mtnlogColor (const MTNLOG_BOOL enable)
 Enable or disable color for messages. More...
 
MTNLOG_BOOL mtnlogCheckColor (void)
 Check if color is supported. More...
 
void mtnlogConsoleOutput (const MTNLOG_BOOL enable)
 Enable or disable outputting log messages into console (stdout) More...
 
void mtnlogFileOutput (const MTNLOG_BOOL enable)
 Enable or disable outputting log messages into the log file. More...
 
void mtnlogSetLevel (const MtnLogLevel level)
 Set logging level. More...
 
void mtnlogSetCallback (const MtnLogCallback cb)
 Set log callback. More...
 
void mtnlogTimestamps (const MTNLOG_BOOL enable)
 Enable or disable log timestamps. More...
 
void mtnlogConsoleTimestamps (const MTNLOG_BOOL enable)
 Enable or disable putting timestamps in console. More...
 
void mtnlogMessage (const MtnLogLevel level, const char *format,...)
 Print a message to the log. More...
 
void mtnlogVMessage (const MtnLogLevel level, const char *format, va_list l)
 Print a message to the log (VA list version) More...
 
void mtnlogMessageTag (const MtnLogLevel level, const char *tag, const char *format,...)
 Print a message to the log with a tag. More...
 
void mtnlogVMessageTag (const MtnLogLevel level, const char *tag, const char *format, va_list l)
 Print a message to the log with a tag (VA list version) More...
 
void mtnlogMessageCInternal (const int line, const char *file, const char *function, const MtnLogLevel level, const char *message,...)
 Internal function for mtnlogMessageC. More...
 
void mtnlogMessageTagCInternal (const int line, const char *file, const char *function, const MtnLogLevel level, const char *tag, const char *message,...)
 Internal function for mtnlogMessageTagC. More...
 

Macro Definition Documentation

◆ MTNLOG_BOOL

#define MTNLOG_BOOL   bool

MtnLog boolean type.

◆ mtnlogMessageC

#define mtnlogMessageC (   level,
  ... 
)    mtnlogMessageCInternal(__LINE__, __FILE__, "", (level), __VA_ARGS__)

Log message with context.

Parameters
levellevel of the message
...variadic arguments including the format string

◆ mtnlogMessageTagC

#define mtnlogMessageTagC (   level,
  tag,
  ... 
)    mtnlogMessageTagCInternal(__LINE__, __FILE__, "", (level), (tag), __VA_ARGS__)

Log message with tag and context.

Parameters
levellevel of the message
tagmessage tag
...variadic arguments including the format string

Typedef Documentation

◆ MtnLogCallback

typedef void(* MtnLogCallback) (MtnLogLevel, const char *, const char *)

Log callback function.

Parameter 1: Log level

Parameter 2: Timestamp

Parameter 3: Message

Enumeration Type Documentation

◆ MtnLogLevel

Enum representing logging level.

Enumerator
MTNLOG_INFO 

Information: Status or progress of the program

MTNLOG_WARNING 

Warning: Something is a bit off, but we can still continue

MTNLOG_ERROR 

Error: We are in trouble!

Function Documentation

◆ mtnlogCheckColor()

MTNLOG_BOOL mtnlogCheckColor ( void  )

Check if color is supported.

On Windows this always returns true.

On non-Windows platforms this checks the TERM environment variable.

◆ mtnlogColor()

void mtnlogColor ( const MTNLOG_BOOL  enable)

Enable or disable color for messages.

Parameters
enableenable or disable color

Color is only supported for platforms that support ANSI escape sequences for colors. This will not change the log file, only console output.

◆ mtnlogConsoleOutput()

void mtnlogConsoleOutput ( const MTNLOG_BOOL  enable)

Enable or disable outputting log messages into console (stdout)

Parameters
enableenable or disable console output

◆ mtnlogConsoleTimestamps()

void mtnlogConsoleTimestamps ( const MTNLOG_BOOL  enable)

Enable or disable putting timestamps in console.

Parameters
enableenable or disable

◆ mtnlogFileOutput()

void mtnlogFileOutput ( const MTNLOG_BOOL  enable)

Enable or disable outputting log messages into the log file.

Parameters
enableEnable ot disable file output

This can be useful if you're working in an environment without a file system or want to only have a log in the console.

◆ mtnlogInit()

void mtnlogInit ( const MtnLogLevel  level,
const char *  logFileName 
)

Initialize logging.

Parameters
levellogging level
logFileNamename of the log file

◆ mtnlogMessage()

void mtnlogMessage ( const MtnLogLevel  level,
const char *  format,
  ... 
)

Print a message to the log.

Parameters
levellevel of the message
formatformatting string

Used the same way as printf.

◆ mtnlogMessageCInternal()

void mtnlogMessageCInternal ( const int  line,
const char *  file,
const char *  function,
const MtnLogLevel  level,
const char *  message,
  ... 
)

Internal function for mtnlogMessageC.

Note
Please use mtnlogMessageC instead of putting the context yourself.
See also
mtnlogMessageC

◆ mtnlogMessageTag()

void mtnlogMessageTag ( const MtnLogLevel  level,
const char *  tag,
const char *  format,
  ... 
)

Print a message to the log with a tag.

Parameters
levellevel of the message
tagmessage tag
formatformatting string
See also
mtnlogMessage

◆ mtnlogMessageTagCInternal()

void mtnlogMessageTagCInternal ( const int  line,
const char *  file,
const char *  function,
const MtnLogLevel  level,
const char *  tag,
const char *  message,
  ... 
)

Internal function for mtnlogMessageTagC.

Note
Please use mtnlogMessageTagC instead of putting the context yourself.
See also
mtnlogMessageTagC

◆ mtnlogSetCallback()

void mtnlogSetCallback ( const MtnLogCallback  cb)

Set log callback.

Parameters
cbcallback

◆ mtnlogSetLevel()

void mtnlogSetLevel ( const MtnLogLevel  level)

Set logging level.

Parameters
levellevel

◆ mtnlogTimestamps()

void mtnlogTimestamps ( const MTNLOG_BOOL  enable)

Enable or disable log timestamps.

Parameters
enableenable or disable

◆ mtnlogVMessage()

void mtnlogVMessage ( const MtnLogLevel  level,
const char *  format,
va_list  l 
)

Print a message to the log (VA list version)

Parameters
levellevel of the message
formatformatting string
lVA list to be used
See also
mtnlogMessage

◆ mtnlogVMessageTag()

void mtnlogVMessageTag ( const MtnLogLevel  level,
const char *  tag,
const char *  format,
va_list  l 
)

Print a message to the log with a tag (VA list version)

Parameters
levellevel of the message
tagmessage tag
formatformatting string
lVA list to be used
See also
mtnlogMessageTag