Lob is a C89, cross-platform, MIT-licensed, statically-compiled logging library.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dirkson 846302a964 Allow disabling runlevels 3 days ago
include Added vlob 3 days ago
scripts Experimental update tinkering with meson 2 weeks ago
src Allow disabling runlevels 3 days ago
.gitignore Added windows cross compilation 4 months ago
.lvimrc Added boksi support. Updated documentation 4 months ago
LICENSE Initial commit 2 years ago
README.md Added vlob 3 days ago
build Experimental update tinkering with meson 2 weeks ago
meson.build Added vlob 3 days ago

README.md

Lob

Lob (or liblob) is a cross-platform, MIT-licensed, statically-compiled logging library written in C89.

It will display errors, warnings, and other messages via stdout, stderr, gui boxes, or direct writes to files. It’s optionally thread safe, and all calls are blocking. It’s designed to be minimal and only include the code you need. It prefers to log successfully over logging quickly, but it should still be quite fast. It should compile on Linux, OSX, and windows.

Example

lob.svg

Hello world

#include <lob_basic.h>
int main() {
	return lob(LOB_ERROR, "Hello %s", "world");
}

Basic Use

To build, type ‘./build -r’. Output is lib/liblob.a , which should be usable in most C projects.

To build examples, type ‘make examples’. Output is bin/test and bin/basic

The externally visible logging function is:

int lob(const lob_level Level, const char * const Format, ...)

To include predefined levels, include “lob_basic.h”. It provides the follow levels:

LOB_ERROR  //Prints to stderr, log.txt, and creates a guibox. Makes lob() return 0.
LOB_WARN   //Prints to stdout and log.txt. Makes lob() return 1.
LOB_INFO   //Prints to stdout. Makes lob() return 1.
LOB_DEBUG  //Prints to stdout. Makes lob() return 1.

Format is a printf-style formatted string, with a newline appended for you. It is followed by a list of variables, in the printf style.

lob()’s return value is determined by its level. The default levels provided by “lob_basic.h” use 0 for LOB_ERROR, and 1 for others.

Available compile flags

Lob is designed to be statically compiled into whatever it’s used in, and as such most configuration options are compile-time flags. This removes the unused feature from lob entirely in most cases.

You’ll need to clean whenever cflags change: ./build -c

To use a flag, use this format

CFLAGS="-DLOB_SOME_FLAG -DLOB_SOME_OTHER_FLAG" ./build -r liblob.a

List of simple compile flags

LOB_NO_TIME        //Disable timestamps
LOB_NO_COLOR       //Disable color output to stdout/err.
LOB_NO_SOURCE_FILE //Disable source file/line number
LOB_NO_ALLOCATE    //If lob runs out of space while processing a gui box, it'll attempt to allocate space. This prevents this behavior.
LOB_NO_FILE        //Disable output method - log file
LOB_NO_STDOUT      //Disable output method - stdout/err
LOB_NO_BOKSI       //Disable output method - Boksi gui boxes
LOB_NO_TINYFD      //Disable output method - tinyfiledialogs gui boxes. Automatically set if Boksi is enabled.

There are also a few more complicated flags.

Example usage:

CFLAGS="-DLOB_TIME_FORMAT=\"[%H:%M:%S] \" -DLOB_BUFFER_SIZE=1024" ./build -r liblob.a

List of more complicated flags

LOB_TIME_FORMAT    //Default "%H:%M:%S" . Uses strftime format.
LOB_RETURN_TYPE    //Default int . You cannot use lob_basic.h if you change this to char*.
LOB_BUFFER_SIZE    //Default 256 . ONLY valid for Boksi or tinyfiledialogs boxes right now. Any message longer than this will result in allocation by default. (See LOB_NO_ALLOCATE)

Advanced Use

Define your own levels! See include/lob_basic.h

If you need to pass in a va_list, you can call “vlob” rather than plain “lob”. It takes all the same arguments, with the exception of a va_list instead of a list of arguments.

TODO

  • Add some method to allow users to introduce their own callbacks.
  • Add some method of internet-capable logging.
  • Add logging to syslog.
  • Add process safety

FAQ

Q: Why “Lob”?

A: Well, it could be clever word play based on the concept of “throwing” errors. Alternatively, I could’ve typo’d the word ‘log’ and decided to just go with it. I’ll let you figure out which one is more likely.