GithubHelp home page GithubHelp logo

logging's Introduction

logging

A small, flexible logging framework for C libraries and applications.

Designed for use in large applications down to embedded systems.

Installing

$ git clone https://github.com/kanemathers/logging.git
$ cd logging
$ make
$ sudo make install

Usage

Include the header:

#include <logging.h>

Programmable

First thing you'll want to do is create your logger:

logger_t *logger = logger_new();

Then create your handlers:

handler_t *console = hconsole_new();
handler_t *file    = hfile_new("/tmp/output.log");
handler_t *syslog  = hsyslog_new("ident", LOG_LOCAL0);

Need to add those handlers to the logger. Specify a priority to filter the output to that handler:

logger_add_handler(logger, console, LOG_DEBUG);
logger_add_handler(logger, file, LOG_DEBUG);
logger_add_handler(logger, syslog, LOG_ERR);

And now you can start firing off log messages:

logger_emit(logger, LOG_DEBUG, "syslog won't see this");
logger_emit(logger, LOG_ERR, "all handlers will %s", "see this");

When you're done, cleanup:

logger_free(logger);

Config

You can also generate a logger instance from a config file:

logger_t *logger = logger_from_config("./config.ini");

Full Example

#include <stdlib.h>
#include <logging.h>

int main()
{
    logger_t *logger = logger_from_config("./config.ini");

    if (!logger)
        return EXIT_FAILURE;

    logger_emit(logger, LOG_DEBUG, "works!\n");

    logger_free(logger);

    return EXIT_SUCCESS;
}

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.