Git Product home page Git Product logo

limlog's Introduction

limlog

Lightweight, easy-to-use and fast logging library, providing only a front-end for log writing.

Header-only, cross-platform which implemented in C++11. 细节分析

limlog uses the singleton pattern and is recommended for simple logging scenarios

Usage

Header only, simply include 'limlog.h'.

#include "limlog.h"

int main() {
  limlog::singleton()->setLogLevel(limlog::kDebug);

  LOG_INFO << 123 << ' ' << 1.23 << ' ' << true << ' ' << "123";
  return 0;
}

A logline format as follow:

//  +-------+------+-----------+------+------+------------+------+
//  | level | time | thread id | logs | file | (function) | line |
//  +-------+------+-----------+------+------+------------+------+

// such as:
INFO 2022-02-28T15:45:56.341+08:00 25332 fuck.cpp:4 123 1.230000 true 123

Logging Output

limlog does not provide a rotation utility for logs, which is required for external programs.

But limlog provides an output interface for users to customize.

#include "limlog.h"

// send log info to remote server.
ssize_t send_to_remote(const char *, size_t n) { 
  // do send
  return 0;
}

int main() {
  limlog::singleton()->setOutput(send_to_remote);

  LOG_INFO << 123 << ' ' << 1.23 << ' ' << true << ' ' << "123";
  return 0;
}

Optimization

Time

see https://github.com/zxhio/time_rfc3339.

Thread local cache thread id

Introduce thread_local to avoid race conditions between threads. And reduce the number of gettid system calls

Number to String

Uses search table to optimise integer and peer search can confirm two characters.

TODO

  1. support more pattern for logging.
  2. support async process.

Reference

  1. Iyengar111/NanoLog, Low Latency C++11 Logging Library.
  2. PlatformLab/NanoLog, Nanolog is an extremely performant nanosecond scale logging system for C++ that exposes a simple printf-like API.
  3. kfifo, kernel ring buffer.
  4. itoa-benchmark, some itoa algorithm, limlog uses search table.

limlog's People

Contributors

zxhio avatar

Watchers

James Cloos 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.