Coder Social home page Coder Social logo

liblog's Introduction

Liblog is a very fast low-overhead logger targeted at developers.
It is not meant for customer use.

Liblog is a tiny daemon which maintains a small shared memory segment
to which your application writes it's messages.  When you need a copy
of the messages you need but run "killall -USR1 lldump" and the shared
memory segment will be written to disk.  New messages overwrite old
ones when the log buffer fills up.  The messages can then be extracted
with the llcat utility.

The interface is very simple.  Logging is initiated with a call to
ll_open(), there are two arguments, the minimum logging level and the
size of the shared memory buffer.  Log levels are defined in liblog.h.
ll_open creates the shared memory segment and starts the daemon.  It
returns 0 on success, -1 on failure.  One writes to the log with calls
to ll_log(), the arguments are the level, a printf style format
string, and a variable number of arguments.  When you're done you
terminate logging with ll_close() which flushes the buffer to disk and
frees the shared memory segment.

Because the shared memory segment has a header in front of your
messages and the messages are not necessarily in order a small utility
is provided to examine the messages, it is called llcat and it takes
one argument, the name of the logfile to be displayed.

It's usage might look something like this:

#include <liblog.h>
int
main(int argc, char **argv)
{
   if (debug) {
      /* log warnings and above, keep last 16k */
      if (ll_open(LL_LVL_WARN, 16*1024) == -1) {
         (void)fprintf(stderr, "failed to open liblog\n");
         return 1;
      }
   }
   ...
   /* log anything above debug */
   (void)ll_setlevel(LL_LVL_DBG);
   if (debug) {
      ll_log(LL_LVL_NOTE, "i: %d str: %s\n, i, s);
   }
   ...
   /* this also flushes to disk */
   ll_close();
   return 0;
}

liblog's People

Contributors

michaelgalassi 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.