EzC
Macros | Typedefs | Enumerations | Functions
ezc_log.h File Reference

Prioritize and write to file your error and debugging messages. More...

#include <stdarg.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define ezc_log(type, message, ...)   (ezc_log__(__FILE__, __LINE__, (type), (message), ##__VA_ARGS__))
 Add message to global log. More...
 

Typedefs

typedef enum ezc_log_t ezc_log_t
 Log severity. More...
 

Enumerations

enum  ezc_log_t { EZC_LOG_INFO = 0, EZC_LOG_WARN, EZC_LOG_ERROR, EZC_LOG_FATAL }
 Log severity. More...
 

Functions

void ezc_log_echo (FILE *dest)
 Set where logs are echoed to. More...
 
char const * ezc_log_get (ezc_log_t type)
 Get most recent message of at least given severity. More...
 
void ezc_log_fwrite ()
 Write the global log to a file. More...
 
void ezc_log_clear ()
 Clear the global log. More...
 

Detailed Description

Prioritize and write to file your error and debugging messages.

Macro Definition Documentation

◆ ezc_log

#define ezc_log (   type,
  message,
  ... 
)    (ezc_log__(__FILE__, __LINE__, (type), (message), ##__VA_ARGS__))

Add message to global log.

This macro accepts variadic arguments printf style. Messages are not echoed to stdout or stderr by default, but this can be changed via ezc_log_echo(FILE *).

Parameters
typeThe message type enum. See ezc_log_t documentation for more info.
messageThe message itself. Supports formatting just like printf.
...printf style variadic arguments.
Returns
N/A

Typedef Documentation

◆ ezc_log_t

typedef enum ezc_log_t ezc_log_t

Log severity.

Helps prioritize your log messages.

Enumeration Type Documentation

◆ ezc_log_t

enum ezc_log_t

Log severity.

Helps prioritize your log messages.

Enumerator
EZC_LOG_INFO 

Low priority. Simply displays diagnostic information.

EZC_LOG_WARN 

Medium priority. Results might be unordinary.

EZC_LOG_ERROR 

High priority. A routine failed and might cause instability.

EZC_LOG_FATAL 

Unignorable priority. LOGS OF THIS TYPE TRIGGER AN ABORT!

Function Documentation

◆ ezc_log_clear()

void ezc_log_clear ( )

Clear the global log.

Clears absolutely everything from info logs to fatal logs.

◆ ezc_log_echo()

void ezc_log_echo ( FILE *  dest)

Set where logs are echoed to.

By default, logs are not echoed.

Parameters
destEcho destination. This can be stdout, stderr, or any file of your choosing.

◆ ezc_log_fwrite()

void ezc_log_fwrite ( )

Write the global log to a file.

The file name is YYYY-MM-DD-HH-MM-SS.error, located in the directory the program was called from. If this file somehow already exists, it is overwritten. This function does not clear the log.

◆ ezc_log_get()

char const* ezc_log_get ( ezc_log_t  type)

Get most recent message of at least given severity.

For example, if the most recent item in the log is of type EZC_LOG_WARN, but ezc_log_get(EZC_LOG_ERROR) is called, it will skip over the warning item and keep stepping back through the log until an EZC_LOG_ERROR item is found.

Parameters
typeThe returned log will be at least as severe as the log type specified by this argument.
Returns
The most recent message in the global log. Returns NULL if there have been no messages since the beginning of the program or the most recent ezc_log_clear(), or if no message of at least type priority was found.