Skip to content

A simple library to output colourized debug/logging to a terminal program like putty

License

Notifications You must be signed in to change notification settings

rmcmillin/log.c-for-embedded

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 

Repository files navigation

log.c

A simple library to output colourized debug/logging to a terminal program like putty

logimage

Usage

log.c and log.h should be dropped into an existing project and compiled along with it.

There are two functions in log.c to be completed by the user:

void uartSendByte(uint8_t byte);
uint32_t getTimestamp ();

uartSendByte requires a driver for your device to put a single byte onto the uart transmit pin (see example for atmega4809)

getTimestamp is required if timestamps or timeoffsets are desired. An RTC or 1 second timer can be used.

The library provides 6 function-like macros for logging:

log_trace(const char *fmt, ...);
log_debug(const char *fmt, ...);
log_info(const char *fmt, ...);
log_warn(const char *fmt, ...);
log_error(const char *fmt, ...);
log_fatal(const char *fmt, ...);

Each function takes a format string similar to printf followed by additional arguments:

I tried to keep things small by not including printf, so the only formatting available is:

Format Description
%d unsigned 16bit integer
%l unsigned 32bit integer
%i binary
%h hex (wihout 0x prefix)
log_trace("Register Contents %i", registerContents);
log_debug("Value: 0x%h", memoryContents);
log_info("i2c read device: %h address: %h contents: %d", slaveAddress, memoryAddress, memoryContents);
log_warn("i2c bus is stuck");
log_error("Failed with error code (%d)", errorCode);
log_fatal("No response");	

Set Log Level

To set the log level, set the definition to desired level

#define LOG_LEVEL	LOG_TRACE	//no log output below this level

Enable Colour

To enable colour, define LOG_USE_COLR

#define LOG_USE_COLOR	 //comment this line if colour not desired

Enable Timestamps

To enable timestamps, define LOG_TIME

#define LOG_TIME	//comment this line if timestamps not desired

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

About

A simple library to output colourized debug/logging to a terminal program like putty

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%