GithubHelp home page GithubHelp logo

clog's Introduction

clog: Logging library in C99

Typical CMake installation process:

$ git clone https://github.com/ashermancinelli/clog.git
$ cd clog
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/install/prefix
$ make
$ make test
$ make install

Example usage can be found in the tests directory.

Simple example:

#include <clog.h>
#include <assert.h>
int main()
{
  int ierr=0;
  ierr=ClogInitialize();assert(!ierr);
  ierr=ClogSetLogLevel(CLOG_LEVEL_INFO);assert(!ierr);
  ierr=ClogLog(CLOG_LEVEL_WARN,"%s","This is a warning.");assert(!ierr);
  ierr=ClogLog(CLOG_LEVEL_INFO,"%s","This is info.");assert(!ierr);
  ierr=ClogLog(CLOG_LEVEL_ERROR,"%s","This is an error.");assert(!ierr);
  ierr=ClogLog(CLOG_LEVEL_ERROR,"%s","This is a multiline\nerror\nmessage.");assert(!ierr);
  ierr=ClogFinalize();assert(!ierr);
  return 0;
}

Output:

$ ./build/tests/testLevels
[09:01:38] [WARNING]: This is a warning.
[09:01:38] [INFO]: This is info.
[09:01:38] [ERROR]: This is an error.
[09:01:38] [ERROR]: This is a multiline
[09:01:38] [ERROR]: error
[09:01:38] [ERROR]: message.

Example of the format API:

#include <clog.h>
int main(void)
{
  int ierr=0;
  ierr=ClogInitialize();CHKERR(ierr);
  ierr=ClogSetLogLevel(CLOG_LEVEL_INFO);CHKERR(ierr);
  ierr=ClogLog(CLOG_LEVEL_WARN,"%s","This is a warning with the default format string.");CHKERR(ierr);
  ierr=ClogLog(CLOG_LEVEL_WARN,"%s","I'm about to change the logger to ouput JSON:");CHKERR(ierr);
  ierr=ClogSetFormat("{\n\t'time':'%s',\n\t'level':'%s',\n\t'message':'%s'\n}\n");CHKERR(ierr);
  ierr=ClogLog(CLOG_LEVEL_ERROR,"%s","Some logging info!");CHKERR(ierr);
  ierr=ClogFinalize();CHKERR(ierr);
  return 0;
}

Output:

$ ./tests/testFormat
[01/18/21 - 12:03PM] [WARNING]: This is a warning with the default format string.
[01/18/21 - 12:03PM] [WARNING]: I'm about to change the logger to ouput JSON:
{
	'time':'01/18/21 - 12:03PM',
	'level':'ERROR',
	'message':'Some logging info!'
}

We also have Pthread/fork join/mpi support if your application is threaded. See interface for details.

clog's People

Contributors

ashermancinelli avatar

Watchers

 avatar  avatar

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.