Skip to content

febits/loguva

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Loguva

Loguva (Log + Uva) is a library that aims to include a simple and lightweight interface for logs.

Features:

  • Multiple log destinations.
  • Multiple log levels.
  • Fancy stdout.

Installation

git clone https://github.com/febits/loguva
cd loguva
make all
sudo make install

Usage

Firstly, you need to include the main header file: loguva.h. Don't forget to pass the -lloguva to the linker.

Basically, the loguva allows adding up to 20 instances of FILE * by calling one of the following functions below:

bool loguva_add_stream(FILE *stream);
FILE *loguva_add_file(const char *path);

Once you call the macro below passing the log level and the message, you are logging:

#define loguva(lv, fmt, ...)                                                   \
  loguva_log(lv, __FILE__, __LINE__, fmt, ##__VA_ARGS__)

Log levels:

enum log_levels { DEBUG, INFO, WARNING, ERROR, FATAL };

Let's suppose that you want to log both STDOUT and some FILE *:

#include <loguva.h>

int main(void) {
    
    loguva_add_stream(stdout);
    loguva_add_file("/tmp/loguva.log");

    int x = 50;

    loguva(DEBUG, "The value of X: %d", x);

    return 0;
}

When you call loguva(), all instances of FILE * will be used to write the full log message. As you can see above, both STDOUT and /tmp/loguva.log.

Samples

Loguva Print from STDOUT

make run_samples

About

A tiny and lightweight log library in ANSI C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published