dianjixz / limlog

limlog is a cross-platform C++ library for logging.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

limlog is a cross-platform C++ library for logging.


Languages

Language:C++ 98.6%Language:Makefile 1.4%