Code Monkey home page Code Monkey logo

zwlog's Introduction

zwlog

zwlog is a simple logging library written with modern C++ features.


Overview

The image below shows how logs are processed in this library.

image


Requirements

  • C++20 or higher
  • CMake

Usage

#include <zwlog/Logger.hpp>
#include <zwlog/LogTargetFile.hpp>
#include <zwlog/LogTargetMessageBox.hpp>
#include <zwlog/DefaultFormatter.hpp>

// Here, namespace is used to make a scope for enumerators instead of enum class
// because you need to cast it to integer explicitly for each use if you use enum class
namespace LogGroup
{
  enum
  {
    Default = 0,
    Fatal
  }
}

// ditto
namespace LogSeverity
{
  enum
  {
    Info = 0,
    Warning,
    Error
  }
}

int main()
{
  // Set tags for severities
  // Tags are used by log formatters
  zwlog::SetSeverity(LogSeverity::Info, "Info");
  zwlog::SetSeverity(LogSeverity::Warning, "Warning");
  zwlog::SetSeverity(LogSeverity::Error, "Error");

  // Create log targets
  // Your logs are written to these targets
  auto file_target = zwlog::LogTargetFile::Create("logs/log.txt");
  auto msgbox_target = zwlog::LogTargetMessageBox::Create();
  
  // Create log formatters 
  // Log formatters are used to add useful information to your logs
  // EX) [Error] Error Occurred!!
  //     -- 15:36:22 PM | File: main.cpp | Line: 32 | Func: main --
  auto default_formatter = zwlog::DefaultFormatter::Create();
  
  // Assign log formatters to log targets
  // (Log targets basically use DefaultFormatter, so you don't have to do this in practice)
  file_target.SetFormatter(default_formatter);
  msgbox_target.SetFormatter(default_formatter);
  
  // Add log targets to the specified group
  zwlog::AddTarget(LogGroup::Default, file_target);
  zwlog::AddTarget(LogGroup::Fatal, file_target);
  zwlog::AddTarget(LogGroup::Fatal, msgbox_target);
  
  // Logs are written to 'log.txt' file
  LOG(LogGroup::Default, LogSeverity::Info) << "My Message!" << ' ' << "Hi!";
  /*
    [Info] My Message! Hi!
    -- 17:22:10 PM | File: main.cpp | Line: 63 | Func: main --
  */
  
  // Logs are written to 'log.txt' file and displayed in the message box
  LOG(LogGroup::Fatal, LogSeverity::Error) << "Fatal Error Occured!";
  /*
    [Error] Fatal Error Occurred!!
    -- 17:22:13 PM | File: main.cpp | Line: 64 | Func: main --
  */
}

zwlog's People

Contributors

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