Logger library enables you to use unified interface to send out or receive data using one function with different parameters. You leave buffer overflows to this library as it handles it all.

Logger library howto guide.

Below is a simple program that outlines the usage of the logger library, The whole function was head-written so there might be some errors, but it is more for a live representation of usage than anything else. If someone would write a nice example program feel free to link it here.

simple usage of logger library

#include "mbed.h"
#include "logger.h"
#include "errno.h"

Ticker printout;
/**
 * \def STASH_BUFFER_LEN
 * size of stash buffer that can be used to store logged data
 */
#define STASH_BUFFER_LEN 70000
/// stash_buffer size
static char stash_buffer[STASH_BUFFER_LEN];

/**
 * Log_pop_periodic is periodically printing the messages until the buffer is empty. 
 * Once the buffer is empty it detaches and waits for another command.
*/
void log_pop_periodic(void)
{
    if( log_pop(L_BTSERIAL,stash_buffer,STASH_BUFFER_LEN) == 1 )
    {
        printout.detach();
    }
}

static int i=0;
static char read_buffer[20];
/**
 * read data from BT serial
*/
void read_from_BT()
{

    if (BTSerial.readable()) {
        read_buffer[i++] = BTSerial.getc();
        // if we read the desired character
        if (read_buffer[i-1] == 'p')
        {
            // start the printout process which will log_pop logged data
            printout.attach(&log_pop_periodic,0.5);
        }
    }    
}

int main()
{
    log_init(L_SERIAL);
    log_init(L_BTSERIAL);
    BTSerial.attach(&read_from_BT);

    // while loop to fill in loads of stinky data
    while (1) {
            // read something, then stash it
            log_stash(L_INFO,print_buffer,strlen(print_buffer),stash_buffer,STASH_BUFFER_LEN);
    }
}

History

Fixed some minor bugz and added clearing of stash buffer once whole chunk is printed to L_SERIAL. Also expanded documentation a bit. default tip

2014-12-31, by Letme [Wed, 31 Dec 2014 22:23:19 +0000] rev 5

Fixed some minor bugz and added clearing of stash buffer once whole chunk is printed to L_SERIAL. Also expanded documentation a bit.


Library now does not define stashed buffer - it is up for user to define it. Also added some input parameter guarding since we are dealing with multiple pointers and we do not want to pass NULL around.

2014-12-31, by Letme [Wed, 31 Dec 2014 22:14:48 +0000] rev 4

Library now does not define stashed buffer - it is up for user to define it. Also added some input parameter guarding since we are dealing with multiple pointers and we do not want to pass NULL around.


First commit of the Logger library. It is helpful when you want to quantify your debug messages and determine print priorities (or log) and when you want to save data in buffer for sending at command (log_pop). Very simple UI created.

2014-12-30, by Letme [Tue, 30 Dec 2014 20:50:31 +0000] rev 3

First commit of the Logger library. It is helpful when you want to quantify your debug messages and determine print priorities (or log) and when you want to save data in buffer for sending at command (log_pop). Very simple UI created.


Switched serial port

2014-09-08, by Letme [Mon, 08 Sep 2014 20:40:27 +0000] rev 2

Switched serial port


Added few more comments

2014-03-29, by Letme [Sat, 29 Mar 2014 10:39:24 +0000] rev 1

Added few more comments


Initial commit

2014-03-01, by Letme [Sat, 01 Mar 2014 23:57:31 +0000] rev 0

Initial commit