Giter Club home page Giter Club logo

liblogger's Introduction

liblogger

liblogger is a simple JSON logger in C.

Use

To use this library, initialize the logger with s_log_init() and call the s_log macro. The latter macro takes a log level, any number of s_log_field_t pointers containing a string key and a log value.

The supported int values are: int, int8, int16, int32, int64 The supported uint values are: uint, uint8, uint16, uint32, uint64

As well as double, and string.

The supported log levels are: trace, debug, info, warn, error, fatal,

For a successful log entry to be made, a key and a value need to be provided. If no value is provided, that field will not be logged.

Example

Build the example:

make example
#include <stdio.h>

#include "logger.h"

int
main(int argc, char **argv)
{
    s_log_init(stdout); 
    s_log(LOG_INFO, 
        s_log_string("msg", "records added successfully"), 
        s_log_uint("count", 2));
    s_log(LOG_INFO, 
        s_log_string("msg", "records added successfully"), 
        s_log_int64("count", 9223372036854775807));
    s_log(LOG_INFO, 
        s_log_string("msg", "record added successfully"), 
        s_log_string("name", "Brian"), 
        s_log_double("elapsed", 5.76));
    s_log(LOG_FATAL, s_log_string("msg", "dead :("));   
}

Expected output:

{ "timestamp": 1541620673, "level": "info", "msg": "records added successfully", "count": 2 }
{ "timestamp": 1541620673, "level": "info", "msg": "records added successfully", "count": 9223372036854775807 }
{ "timestamp": 1541620673, "level": "info", "msg": "records added partially", "count": 3 }
{ "timestamp": 1541620673, "level": "info", "msg": "record added successfully", "name": "Brian", "elapsed": 5.7599999999999998 }

Write to a log file:

FILE *f = fopen("file.log", "w");
s_log_init(f);
s_log(log_INFO, s_log_string("msg", "records added successfully"), s_log_uint8("count", 2));
fclose(f);

Requirements

Lots of thanks to Ayan George for the help with getting this where it is.

Contact

Brian Downs @bdowns328

License

BSD 2 Clause License.

liblogger's People

Contributors

briandowns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

caoyongren

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.