Rudiments

Public Member Functions | Static Public Member Functions | List of all members
logger Class Reference

## Public Member Functions
| logger ()
| ~logger ()
void | addLogDestination (logdestination *logdest)
void | removeLogDestination (logdestination *logdest)
void | removeAllLogDestinations ()
void | setIndent (char ch)
char | getIndent ()
void | setLogLevel (uint8_t level)
uint8_t | getLogLevel ()
void | start (uint8_t level, const char *header, uint32_t indent, const char *string)
void | write (uint8_t level, const char *header, uint32_t indent, const char *format,...)
void | write (uint8_t level, const char *header, uint32_t indent, const char *format, va_list *argp)
void | end (uint8_t level, const char *header, uint32_t indent)

## Static Public Member Functions
static char * | logHeader (const char *name)

## Detailed Description

The logger class and associated logdestination classes provide methods for logging data from an application. The following destinations are supported: file, syslog, stdout and stderr

To use these classes: instantiate one or more logdestinations, instantiate a logger, and add the logdestination instance(s) to the logger class instance using addLogDestination(). Then, each call to a logger class method will output logging information to each of the logdestinations in seqence.

## Constructor & Destructor Documentation

## ◆ logger()

logger::logger | ( |  | ) |

Creates an instance of the logger class.

## ◆ ~logger()

logger::~logger | ( |  | ) |

Deletes this instance of the logger class.

## Member Function Documentation

## ◆ addLogDestination()

void logger::addLogDestination | ( | logdestination * | logdest | ) |

Add "logdest" to the list of destinations that log entries will be written to.

## ◆ end()

void logger::end | ( | uint8_t | level,
|  | const char * | header,
|  | uint32_t | indent
| ) |  |

If the current logging level is equal to or greater than "level", then writes "header", followed by "indent" indentations, followed by "}" as a single log entry.

## ◆ getIndent()

char logger::getIndent | ( |  | ) |

Returns the character currently used when indenting.

## ◆ getLogLevel()

uint8_t logger::getLogLevel | ( |  | ) |

Returns the logging level.

## ◆ logHeader()

static char* logger::logHeader | ( | const char * | name | ) |
| static

Returns a string containing the current date, followed by "name", followed by the process id in brackets. For example:

01/05/2002 12:54:23 myprogram [2421]

Note that this method allocates a string internally and returns it. This string must be deleted by the calling program.

Note that this method uses getSystemDateAndTime() from the datetime class. If you are using logHeader() in a multi-threaded application, you must supply a mutex to the datetime class using it's setTimeMutex() method.

## ◆ removeAllLogDestinations()

void logger::removeAllLogDestinations | ( |  | ) |

Remove all entries from the list of destinations that log entries will be written to.

## ◆ removeLogDestination()

void logger::removeLogDestination | ( | logdestination * | logdest | ) |

Remove "logdest" from the list of destinations that log entries will be written to.

## ◆ setIndent()

void logger::setIndent | ( | char | ch | ) |

Sets the character to be used when indenting to "ch".

## ◆ setLogLevel()

void logger::setLogLevel | ( | uint8_t | level | ) |

Sets the logging level to "level".

## ◆ start()

void logger::start | ( | uint8_t | level,
|  | const char * | header,
|  | uint32_t | indent,
|  | const char * | string
| ) |  |

If the current logging level is equal to or greater than "level", then writes "header", followed by "indent" indentations, followed by "string" followed by " {" as a single log entry.

## ◆ write() [1/2]

void logger::write | ( | uint8_t | level,
|  | const char * | header,
|  | uint32_t | indent,
|  | const char * | format,
|  | va_list * | argp
| ) |  |

If the current logging level is equal to or greater than "level", then writes "header", followed by "indent" indentations, followed by "va_list" formatted using "format" as a single log entry.

## ◆ write() [2/2]

void logger::write | ( | uint8_t | level,
|  | const char * | header,
|  | uint32_t | indent,
|  | const char * | format,
|  |  | ...
| ) |  |

If the current logging level is equal to or greater than "level", then writes "header", followed by "indent" indentations, followed by "..." formatted using "format" as a single log entry.