NVMLib  very early alpha
A library to optimally use a Hybrid RAM setup.
log.h File Reference
#include <time.h>
#include <string.h>
#include "globals.h"
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _FILE   strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__
 
#define NO_LOG   0x00
 
#define ERROR_LEVEL   0x01
 
#define INFO_LEVEL   0x02
 
#define DEBUG_LEVEL   0x03
 
#define LOG_LEVEL   DEBUG_LEVEL
 
#define PRINTFUNCTION(format, ...)   fprintf(MAIN_LOG_FILE, format, __VA_ARGS__); fflush(MAIN_LOG_FILE)
 
#define LOG_FMT   "%s | %-7s | %-15s | %s:%d | "
 
#define LOG_ARGS(LOG_TAG)   timenow(), LOG_TAG, _FILE, __FUNCTION__, __LINE__
 
#define NEWLINE   "\n"
 
#define ERROR_TAG   "ERROR"
 
#define INFO_TAG   "INFO"
 
#define DEBUG_TAG   "DEBUG"
 
#define LOG_DEBUG(message, args...)   PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(DEBUG_TAG), ## args)
 
#define LOG_INFO(message, args...)   PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(INFO_TAG), ## args)
 
#define LOG_ERROR(message, args...)   PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(ERROR_TAG), ## args)
 
#define LOG_IF_ERROR(condition, message, args...)   if (condition) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(ERROR_TAG), ## args)
 

Functions

static char * timenow ()
 

Detailed Description

The file contains the logging macros

Each of the macros behave like printf()

Sample usage:

LOG_DEBUG("Maybe i can touch this button...");
LOG_INFO("Pressure is dropping...");
LOG_ERROR("Houston we have a problem!");
int going_down = 1;
LOG_IF_ERROR(going_down, "i'm going down... if only i had used macro-logger...");

Definition in file log.h.

Macro Definition Documentation

◆ _FILE

#define _FILE   strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__

Definition at line 26 of file log.h.

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   0x03

Definition at line 31 of file log.h.

◆ DEBUG_TAG

#define DEBUG_TAG   "DEBUG"

Definition at line 46 of file log.h.

◆ ERROR_LEVEL

#define ERROR_LEVEL   0x01

Definition at line 29 of file log.h.

◆ ERROR_TAG

#define ERROR_TAG   "ERROR"

Definition at line 44 of file log.h.

◆ INFO_LEVEL

#define INFO_LEVEL   0x02

Definition at line 30 of file log.h.

◆ INFO_TAG

#define INFO_TAG   "INFO"

Definition at line 45 of file log.h.

◆ LOG_ARGS

#define LOG_ARGS (   LOG_TAG)    timenow(), LOG_TAG, _FILE, __FUNCTION__, __LINE__

Definition at line 40 of file log.h.

◆ LOG_DEBUG

#define LOG_DEBUG (   message,
  args... 
)    PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(DEBUG_TAG), ## args)

Definition at line 49 of file log.h.

◆ LOG_ERROR

#define LOG_ERROR (   message,
  args... 
)    PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(ERROR_TAG), ## args)

Definition at line 61 of file log.h.

◆ LOG_FMT

#define LOG_FMT   "%s | %-7s | %-15s | %s:%d | "

Definition at line 39 of file log.h.

◆ LOG_IF_ERROR

#define LOG_IF_ERROR (   condition,
  message,
  args... 
)    if (condition) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(ERROR_TAG), ## args)

Definition at line 67 of file log.h.

◆ LOG_INFO

#define LOG_INFO (   message,
  args... 
)    PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(INFO_TAG), ## args)

Definition at line 55 of file log.h.

◆ LOG_LEVEL

#define LOG_LEVEL   DEBUG_LEVEL

Definition at line 34 of file log.h.

◆ NEWLINE

#define NEWLINE   "\n"

Definition at line 42 of file log.h.

◆ NO_LOG

#define NO_LOG   0x00

Definition at line 28 of file log.h.

◆ PRINTFUNCTION

#define PRINTFUNCTION (   format,
  ... 
)    fprintf(MAIN_LOG_FILE, format, __VA_ARGS__); fflush(MAIN_LOG_FILE)

Definition at line 37 of file log.h.

Function Documentation

◆ timenow()

static char * timenow ( )
inlinestatic

Definition at line 71 of file log.h.

LOG_INFO
#define LOG_INFO(message, args...)
Definition: log.h:54
LOG_ERROR
#define LOG_ERROR(message, args...)
Definition: log.h:60
LOG_DEBUG
#define LOG_DEBUG(message, args...)
Definition: log.h:48
LOG_IF_ERROR
#define LOG_IF_ERROR(condition, message, args...)
Definition: log.h:66