GithubHelp home page GithubHelp logo

alpsmonaco / simplelog Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 14 KB

You just need to log,so why bother?header-only,single and tiny cpp log lib here!

License: MIT License

CMake 17.62% C++ 82.07% C 0.31%
cpp easy-to-use header-only simple-api thread-safe tiny cross-platform log logging logging-lib

simplelog's Introduction

simplelog

simplelog a header only log library and aims to provide out-of-the-box log feature and simple API.
It is super tiny and the lines of the code is about 150 but still thread safe.
You just have to log in most scenarios,so why bother?

Application Scenarios

small projects or non-performance-sensitive projects,just include it and log,no further configuration need to set.

Quick Start

#include <simple_log.hpp>
namespace sl = simplelog;

int main(int argc, char** argv)
{
  sl::Log::Info("info message");
  sl::Log::Error("error message");
  sl::Log::Debug("debug message");
}

Log Name

By default,the log file name is your executable name.Assumes that your executable name is calculate,
then a file calculate.log will be created and logged to whenever any simple::Log function is called.
You could also define macro SIMPLE_LOG_FILENAME to custom your own log name instead of executable name.

#define SIMPLE_LOG_FILENAME "trivial.log"
#include <simple_log.hpp>

...

Console

By default,simplelog will also print log content to stdout.
You could define macro SIMPLPE_LOG_NO_PRINT to disable it.

#define SIMPLPE_LOG_NO_PRINT
#include <simple_log.hpp>

...

Design

The performance of a widely used C++ log library is normally decent,but it is also huge and perhaps hard to configure.
The library provides simple api and header file that make it easy for anyone to read or DIY.

Thread Safety

On Windows an one-time output stream operation is thread safe.

std::string s;
std::ostream os;
// it is thread safe on Windows.
os << s;

// not thread safe because it is a two-time
// output stream operation.
os << s << std::endl

So on windows,the library use system io to keep log content in sync.

But on Linux,an one-time output stream operation could be thread safe or not.
It is depends on Linux release version or kernel version.
So there's a mutex to keep log content in sync on Linux version.

Performance

This library is not designed for high performance scenarios.
But on a small project or a non-performance-sensitive project,this library is easy to use and fast to begin coding.
It is also strange when the size of a log library is larger than your own project.
You could create a thread pool and then call simplelog::Log function to improve speed because
it is thread safe.

simplelog's People

Contributors

alpsmonaco avatar

Stargazers

 avatar

Watchers

 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.