LogWriter

Write error messages to STDERR for diagnostic purposes.  This module is not thread safe.

Summary
LogWriterWrite error messages to STDERR for diagnostic purposes.
CopyrightThis program is free software.
Files
C-kern/api/io/writer/log/logwriter.hHeader file of LogWriter.
C-kern/io/writer/log/logwriter.cImplementation file LogWriter impl.
Types
struct logwriter_tExports logwriter_t.
struct logwriter_chan_tExports logwriter_chan_t.
Functions
test
unittest_io_writer_log_logwriterTests <initthread_logwriter> and functionality of logwriter_t.
logwriter_tA logwriter writes the console channel messages to STDOUT any other channels to STDERR.
addrAddress of allocated buffer.
sizeSize in bytes of allocated buffer.
chanArray of logwriter_chan_t.
initthread
interface_logwriterThis function is called from <init_threadcontext>.
lifetime
logwriter_FREEStatic initializer.
init_logwriterAllocates memory for the structure and initializes all variables to default values.
free_logwriterFrees resources and frees memory of log object.
query
getbuffer_logwriterReturns content of internal buffer corrseponding to channel as C-string.
getstate_logwriterReturns current log_state_e of channel (log_channel_e).
compare_logwriterReturns 0 if logbuffer compares equal to channel content of lgwrt.
config
setstate_logwriterChange log_state_e of log_channel_e channel to logstate.
change
clearbuffer_logwriterClears log buffer (sets length of logbuffer to 0).
flushbuffer_logwriterWrites content of buffer to STDERR or configured file descriptor and clears log buffer.
printf_logwriterWrites new log entry to internal buffer.
printtext_logwriterWrites a text resource to internal buffer.
vprintf_logwriterSame as printf_logwriter except that variadic arguments are replaced by args.
inline implementation

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/io/writer/log/logwriter.h

Header file of LogWriter.

C-kern/io/writer/log/logwriter.c

Implementation file LogWriter impl.

Types

struct logwriter_t

typedef struct logwriter_t logwriter_t

Exports logwriter_t.

struct logwriter_chan_t

typedef struct logwriter_chan_t logwriter_chan_t

Exports logwriter_chan_t.

Functions

Summary
test
unittest_io_writer_log_logwriterTests <initthread_logwriter> and functionality of logwriter_t.

test

unittest_io_writer_log_logwriter

int unittest_io_writer_log_logwriter(void)

Tests <initthread_logwriter> and functionality of logwriter_t.

logwriter_t

struct logwriter_t

A logwriter writes the console channel messages to STDOUT any other channels to STDERR.  Before anything is written out the messages are stored in an internal buffer.  If less then log_config_MINSIZE plus “terminating \0 byte” bytes are free the buffer is written out (flushed) before any new mesage is appended.  If messages should be appended the buffer is not written out until the last message was appended.  In this case messages are truncated if they are bigger than log_config_MINSIZE.

Threads

In case of KONFIG_SUBSYS_THREAD is not defined static logmain_t is used instead of logwriter_t.

Summary
addrAddress of allocated buffer.
sizeSize in bytes of allocated buffer.
chanArray of logwriter_chan_t.
initthread
interface_logwriterThis function is called from <init_threadcontext>.
lifetime
logwriter_FREEStatic initializer.
init_logwriterAllocates memory for the structure and initializes all variables to default values.
free_logwriterFrees resources and frees memory of log object.
query
getbuffer_logwriterReturns content of internal buffer corrseponding to channel as C-string.
getstate_logwriterReturns current log_state_e of channel (log_channel_e).
compare_logwriterReturns 0 if logbuffer compares equal to channel content of lgwrt.
config
setstate_logwriterChange log_state_e of log_channel_e channel to logstate.
change
clearbuffer_logwriterClears log buffer (sets length of logbuffer to 0).
flushbuffer_logwriterWrites content of buffer to STDERR or configured file descriptor and clears log buffer.
printf_logwriterWrites new log entry to internal buffer.
printtext_logwriterWrites a text resource to internal buffer.
vprintf_logwriterSame as printf_logwriter except that variadic arguments are replaced by args.

addr

uint8_t *addr

Address of allocated buffer.

size

size_t size

Size in bytes of allocated buffer.

chan

logwriter_chan_t *chan

Array of logwriter_chan_t.  A log_channel_e is mapped to a logwriter_chan_t with help of this array.

initthread

interface_logwriter

struct log_it * interface_logwriter(void)

This function is called from <init_threadcontext>.  Used to initialize interface of log_t.

lifetime

logwriter_FREE

#define logwriter_FREE { 0, 0, 0 }

Static initializer.

init_logwriter

int init_logwriter(/*out*/logwriter_t *lgwrt)

Allocates memory for the structure and initializes all variables to default values.  The default configuration is to write the log to standard error.  This log service is not thread safe.  So use it only within a single thread.

free_logwriter

int free_logwriter(logwriter_t *lgwrt)

Frees resources and frees memory of log object.  In case the function is called more than it does nothing.

query

getbuffer_logwriter

void getbuffer_logwriter(const logwriter_t *lgwrt,
uint8_t channel,
/*out*/uint8_t **buffer,
/*out*/size_t *size)

Returns content of internal buffer corrseponding to channel as C-string.  The string has a trailing NULL byte, i.e. buffer[size] == 0.  The address of the buffer is valid as long as no call to free_logwriter is made.  The content changes if the buffer is flushed or cleared and new log entries are written.  Do not free the returned buffer.  It points to an internal buffer used by the implementation.

getstate_logwriter

uint8_t getstate_logwriter(const logwriter_t *lgwrt,
uint8_t channel)

Returns current log_state_e of channel (log_channel_e).

compare_logwriter

int compare_logwriter(const logwriter_t *lgwrt,
uint8_t channel,
size_t logsize,
const uint8_t logbuffer[logsize])

Returns 0 if logbuffer compares equal to channel content of lgwrt.  The call is delegated to <compare_logbuffer>.

config

setstate_logwriter

void setstate_logwriter(logwriter_t *lgwrt,
uint8_t channel,
uint8_t logstate)

Change log_state_e of log_channel_e channel to logstate.

change

clearbuffer_logwriter

void clearbuffer_logwriter(logwriter_t *lgwrt,
uint8_t channel)

Clears log buffer (sets length of logbuffer to 0).  This call is ignored if the log is not configured to be in buffered mode.

flushbuffer_logwriter

void flushbuffer_logwriter(logwriter_t *lgwrt,
uint8_t channel)

Writes content of buffer to STDERR or configured file descriptor and clears log buffer.  This call is ignored if the log is not configured to be in buffered mode.

printf_logwriter

void printf_logwriter(
   logwriter_t *lgwrt,
   uint8_t channel,
   uint8_t flags,
   const struct log_header_t *header,
   const char *format,
    ...
) __attribute__ ((__format__ (__printf__, 5, 6)))

Writes new log entry to internal buffer.  If the entry is bigger than log_config_MINSIZE it may be truncated if internal buffer size is lower.

printtext_logwriter

void printtext_logwriter(logwriter_t *lgwrt,
uint8_t channel,
uint8_t flags,
const struct log_header_t *header,
log_text_f textf,
 ...)

Writes a text resource to internal buffer.  If the entry is bigger than log_config_MINSIZE it may be truncated if internal buffer size is lower.

vprintf_logwriter

void vprintf_logwriter(logwriter_t *lgwrt,
uint8_t channel,
uint8_t flags,
const struct log_header_t *header,
const char *format,
va_list args)

Same as printf_logwriter except that variadic arguments are replaced by args.  Function used internally to implement printf_logwriter.

inline implementation

Write error messages to STDERR for diagnostic purposes.
Implements logging of error messages to standard error channel.
typedef struct logwriter_t logwriter_t
Exports logwriter_t.
struct logwriter_t
A logwriter writes the console channel messages to STDOUT any other channels to STDERR.
typedef struct logwriter_chan_t logwriter_chan_t
Exports logwriter_chan_t.
struct logwriter_chan_t
Extends logbuffer_t with isappend mode and log_state_e.
int unittest_io_writer_log_logwriter(void)
Tests initthread_logwriter and functionality of logwriter_t.
uint8_t *addr
Address of allocated buffer.
size_t size
Size in bytes of allocated buffer.
logwriter_chan_t *chan
Array of logwriter_chan_t.
struct log_it * interface_logwriter(void)
This function is called from init_threadcontext.
#define logwriter_FREE { 0, 0, 0 }
Static initializer.
int init_logwriter(/*out*/logwriter_t *lgwrt)
Allocates memory for the structure and initializes all variables to default values.
int free_logwriter(logwriter_t *lgwrt)
Frees resources and frees memory of log object.
void getbuffer_logwriter(const logwriter_t *lgwrt,
uint8_t channel,
/*out*/uint8_t **buffer,
/*out*/size_t *size)
Returns content of internal buffer corrseponding to channel as C-string.
uint8_t getstate_logwriter(const logwriter_t *lgwrt,
uint8_t channel)
Returns current log_state_e of channel (log_channel_e).
Used to configure the state of a log_channel_e.
Used to switch between log channels.
int compare_logwriter(const logwriter_t *lgwrt,
uint8_t channel,
size_t logsize,
const uint8_t logbuffer[logsize])
Returns 0 if logbuffer compares equal to channel content of lgwrt.
void setstate_logwriter(logwriter_t *lgwrt,
uint8_t channel,
uint8_t logstate)
Change log_state_e of log_channel_e channel to logstate.
void clearbuffer_logwriter(logwriter_t *lgwrt,
uint8_t channel)
Clears log buffer (sets length of logbuffer to 0).
void flushbuffer_logwriter(logwriter_t *lgwrt,
uint8_t channel)
Writes content of buffer to STDERR or configured file descriptor and clears log buffer.
void printf_logwriter(
   logwriter_t *lgwrt,
   uint8_t channel,
   uint8_t flags,
   const struct log_header_t *header,
   const char *format,
    ...
) __attribute__ ((__format__ (__printf__, 5, 6)))
Writes new log entry to internal buffer.
void printtext_logwriter(logwriter_t *lgwrt,
uint8_t channel,
uint8_t flags,
const struct log_header_t *header,
log_text_f textf,
 ...)
Writes a text resource to internal buffer.
void vprintf_logwriter(logwriter_t *lgwrt,
uint8_t channel,
uint8_t flags,
const struct log_header_t *header,
const char *format,
va_list args)
Same as printf_logwriter except that variadic arguments are replaced by args.
struct logmain_t
No object necessary.
iobj_DECLARE(log_t,
log)
Uses iobj_DECLARE to declare object supporting interface log_it.
The minimum size in bytes of one log entry before it is possibly truncated.
Close