Code Monkey home page Code Monkey logo

bonfire's Introduction

Bonfire

Overview

Bonfire is a lighweight threaded logger written in C++ and designed for C++. Single threaded logic would require a logger to open and close the file every time the logger needed to write an entry to the file. This is a tremendous amount of overhead that could be delegated to a different thread. Bonfire is designed to do exactly that, offload most of the overhead of file operations to a different thread.

QuickStart

To start using the logger:

  1. Inlclude the header
  2. Instantiate a Logger object
  3. Log away!
#include "Bonfire.hpp"

int main(int argc, char* argv[]) {
	/* Instantiage a logger object */
	Logger logger = Logger("bonFireLogger", 1);

	/ *Add a file handler to the logger */
	logger.addFileHandler("log.txt", "", "%L--%N--%D--%M", "DEBUG");

	/* Add a terminal handler to the logger	*/
	logger.addTerminalHandler("[%L] [&5%N&] [%D] [%M]", "DEBUG");

	/* Log away */
	logger.debug("For debug purposes only1");
	logger.debug("For debug purposes only2");
	logger.info("Hello world1");
	logger.info("Hello world2");
	logger.warning("Uh oh something's wrong!");
	logger.error("There's an error");
	logger.critical("Oh no, I think I might fall1");
	logger.critical("Oh no, I think I might fall2");
}

Example Terminal Output

img

Example File Output

img

A Queue Between Two Threads

The Logger class has a queue to mediate between the two threads. When the main thread logs a message ex: log.info("task complete!");, the message is added to the queue. When you instantiated the logger object, a background listener thread was started that periodically checks the queue for any data to write. If there is data present, the listener thread write the data to the designate log file. This relieves the burden of file interactions from the main thread.

When the Logger destructor is called, the listener thread finishes writing the remaining data in the queue to the file. Then joins the main thread.

Log Levels

The log levels follow the log levels defined in Python.

Level
DEBUG
INFO
WARNING
ERROR
CRITICAL

Handlers

bonfire's People

Contributors

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