MentOS  0.8.0
The Mentoring Operating System
Macros | Functions
debug.h File Reference

Debugging primitives. More...

Go to the source code of this file.

Macros

#define __DEBUG_LEVEL__   LOGLEVEL_NOTICE
 Defines the debug level, by default we set it to notice.
 
#define __DEBUG_HEADER__   0
 Header for identifying outputs coming from a mechanism.
 
#define __FILENAME__   (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
 Extract the filename from the full path provided by FILE.
 
#define pr_default(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_DEFAULT, __VA_ARGS__)
 Prints a default message, which is always shown.
 
#define pr_emerg(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_EMERG, __VA_ARGS__)
 Prints an emergency message.
 
#define pr_alert(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_ALERT, __VA_ARGS__)
 Prints an alert message.
 
#define pr_crit(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_CRIT, __VA_ARGS__)
 Prints a critical message.
 
#define pr_err(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_ERR, __VA_ARGS__)
 Prints an error message.
 
#define pr_warning(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_WARNING, __VA_ARGS__)
 Prints a warning message.
 
#define pr_notice(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_NOTICE, __VA_ARGS__)
 Prints a notice message.
 
#define pr_info(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_INFO, __VA_ARGS__)
 Prints a info message.
 
#define pr_debug(...)   dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_DEBUG, __VA_ARGS__)
 Prints a debug message.
 

Functions

void set_log_level (int level)
 Sets the loglevel. More...
 
int get_log_level (void)
 Returns the current loglevel. More...
 
void dbg_putchar (char c)
 Prints the given character to debug output. More...
 
void dbg_puts (const char *s)
 Prints the given string to debug output. More...
 
void dbg_printf (const char *file, const char *fun, int line, char *header, short log_level, const char *format,...)
 Prints the given string to the debug output. More...
 
const char * to_human_size (unsigned long bytes)
 Transforms the given amount of bytes to a readable string. More...
 
const char * dec_to_binary (unsigned long value, unsigned length)
 Transforms the given value to a binary string. More...
 

Detailed Description

Debugging primitives.

Function Documentation

◆ dbg_printf()

void dbg_printf ( const char *  file,
const char *  fun,
int  line,
char *  header,
short  log_level,
const char *  format,
  ... 
)

Prints the given string to the debug output.

Parameters
filethe name of the file.
funthe name of the function.
linethe line inside the file.
headerthe header to print.
log_levelthe log level.
formatthe format to used, see printf.
...the list of arguments.

◆ dbg_putchar()

void dbg_putchar ( char  c)

Prints the given character to debug output.

Parameters
cThe character to print.

◆ dbg_puts()

void dbg_puts ( const char *  s)

Prints the given string to debug output.

Parameters
sThe string to print.

◆ dec_to_binary()

const char* dec_to_binary ( unsigned long  value,
unsigned  length 
)

Transforms the given value to a binary string.

Parameters
valueto print.
lengthof the binary output.
Returns
String representing the binary value.

◆ get_log_level()

int get_log_level ( void  )

Returns the current loglevel.

Returns
The current loglevel

◆ set_log_level()

void set_log_level ( int  level)

Sets the loglevel.

Parameters
levelThe new loglevel.

◆ to_human_size()

const char* to_human_size ( unsigned long  bytes)

Transforms the given amount of bytes to a readable string.

Parameters
bytesThe bytes to turn to string.
Returns
String representing the bytes in human readable form.