common logger utility module in go

Overview

Log & Go

This is common logging utility tht is implemented only just for fun :)

I will be giving the details about how to use this utility to log every event occurred in your applications.

Steps

Step 1

go get github.com/yukselcodingwithyou/[email protected]

This command above is necessary for you to use this utility in your application.

Step 2

import logger "github.com/yukselcodingwithyou/logandgo"

Import the downloaded utility to your go files, as visualized above.

Step 3

Create a new logger with a format and level as you wish, format and level information should be like below.

  1. LogLevels

    • PANIC = 0
    • ERROR = 1
    • WARN = 2
    • INFO = 3
    • DEBUG = 4
  2. Formats

    • JSON
    • TEXT

Examples

  • JSON Logger Example

The example below is going to log in WARN level with JSON format. In case you have configured your log level in application level to be WARN, then our logger utility will not log INFO or above levels but just PANIC, ERROR, WARN levels

package main
import logger "github.com/yukselcodingwithyou/logandgo"
func main() {
    jsonLogger := logger.NewLogger(logger.JSON, 2)
    jsonLogger.Debug(logger.LogFields{
        "title": "title",
        "reason": "debug",
        "payload": "payload",
    })
    jsonLogger.Error(logger.LogFields{
        "title": "title",
        "reason": "error",
        "payload": "payload",
    })
    jsonLogger.Info(logger.LogFields{
        "title": "title",
        "reason": "info",
        "payload": "payload",
    })
    jsonLogger.Panic(logger.LogFields{
        "title": "title",
        "reason": "panic",
        "payload": "payload",
    })
    jsonLogger.Warn(logger.LogFields{
        "title": "title",
        "reason": "warn",
        "payload": "payload",
    })
}
  • JSON Logger Output Example

    ERROR: 2021/11/21 16:12:00 main.go:14: {"payload":"payload","reason":"error","title":"title"}

    PANIC: 2021/11/21 16:12:00 main.go:26: {"payload":"payload","reason":"panic","title":"title"}

    WARNING: 2021/11/21 16:12:00 main.go:32: {"payload":"payload","reason":"warn","title":"title"}

  • TEXT Logger Example

The example below is going to log in ALL levels defined with TEXT format.

  package main
  
  import logger "github.com/yukselcodingwithyou/logandgo"

  func main() {

     textLogger := logger.NewLogger(logger.TEXT, 4)
    
     textLogger.Debug(logger.LogFields{
        "title": "title",
        "reason": "debug",
        "payload": "payload",
     })

     textLogger.Error(logger.LogFields{
        "title": "title",
        "reason": "error",
        "payload": "payload",
    })
     
     textLogger.Info(logger.LogFields{
        "title": "title",
        "reason": "info",
        "payload": "payload",
     })
    
     textLogger.Panic(logger.LogFields{
          "title": "title",
          "reason": "panic",
          "payload": "payload",
     })
    
     textLogger.Warn(logger.LogFields{
          "title": "title",
          "reason": "warn",
          "payload": "payload",
     })
  }
  • TEXT Logger Output Example

DEBUG: 2021/11/21 16:39:06 main.go:8: title=title reason=debug payload=payload

ERROR: 2021/11/21 16:39:06 main.go:14: reason=error payload=payload title=title

INFO: 2021/11/21 16:39:06 main.go:20: reason=info payload=payload title=title

PANIC: 2021/11/21 16:39:06 main.go:26: title=title reason=panic payload=payload

WARNING: 2021/11/21 16:39:06 main.go:32: title=title reason=warn payload=payload

Releases(v1.1.2)
Owner
Yüksel Özdemir
Software Engineer
Yüksel Özdemir
Logger - Simple logger without written with std pkg

Go-Logger Simple usage is: package main

MaskedTrench 2 Jan 2, 2022
Logger - A thin wrapper of uber-go/zap logger for personal project

a thin wraper of uber-go/zap logger for personal project 0. thanks uber-go/zap B

tsingson 1 Jun 16, 2022
A reusable logger module for basic logging, written in Go

logger A reusable logger module for basic logging, written in Go. Usage Client p

Praveen Ravichandran 1 Jan 8, 2022
A project that adds color to golang's logger module

logger A project that adds color to golang's log module Installation go get github.com/christopher18/logger Usage // Import the module import "github

null 0 Dec 28, 2021
Go-logger - A sample go module that I stood up quickly to learn how remote modules work in go

go-logger A sample go module that I stood up quickly to learn how remote modules

Stephen Ramirez 0 Jan 9, 2022
A logger, for Go

Go-Log A logger, for Go! It's sort of log and code.google.com/p/log4go compatible, so in most cases can be used without any code changes. Breaking cha

Ian Kent 38 May 12, 2022
Simple logger for Go programs. Allows custom formats for messages.

go-logger A simple go logger for easy logging in your programs. Allows setting custom format for messages. Preview Install go get github.com/apsdehal/

Amanpreet Singh 276 Jun 14, 2022
Loggly Hooks for GO Logrus logger

Loggly Hooks for Logrus Usage package main import ( "github.com/sirupsen/logrus" "github.com/sebest/logrusly" ) var logglyToken string = "YOUR_LOG

Sebest 27 Jul 27, 2021
A 12-factor app logger built for performance and happy development

logxi log XI is a structured 12-factor app logger built for speed and happy development. Simpler. Sane no-configuration defaults out of the box. Faste

Mario Gutierrez 348 Jun 25, 2022
Dead simple, super fast, zero allocation and modular logger for Golang

Onelog Onelog is a dead simple but very efficient JSON logger. It is one of the fastest JSON logger out there. Also, it is one of the logger with the

Francois Parquet 399 Jun 16, 2022
A logger for Go SQL database driver without modify existing *sql.DB stdlib usage.

SQLDB-Logger A logger for Go SQL database driver without modify existing *sql.DB stdlib usage. Colored console writer output above only for sample/dev

Sarjono Mukti Aji 230 Aug 2, 2022
xlog is a logger for net/context aware HTTP applications

⚠️ Check zerolog, the successor of xlog. HTTP Handler Logger xlog is a logger for net/context aware HTTP applications. Unlike most loggers, xlog will

Olivier Poitrey 135 Nov 22, 2021
Zero Allocation JSON Logger

Zero Allocation JSON Logger The zerolog package provides a fast and simple logger dedicated to JSON output. Zerolog's API is designed to provide both

Olivier Poitrey 6.7k Aug 5, 2022
A powerful zero-dependency json logger.

ZKits Logger Library About This package is a library of ZKits project. This is a zero-dependency standard JSON log library that supports structured JS

Qingshan Luo 16 Jun 15, 2022
Configurable Logger for Go

Timber! This is a logger implementation that supports multiple log levels, multiple output destinations with configurable formats and levels for each.

DeNA SF 66 Jun 28, 2022
A feature-rich and easy to use logger for golang

A feature-rich and easy to use logger for golang ?? Install ?? Common Logs lumber.Success() lumber.Info() lumber.Debug() lumber.Warning()

Matthew Gleich 50 Jul 20, 2022
A minimal and extensible structured logger

⚠️ PRE-RELEASE ⚠️ DO NOT IMPORT THIS MODULE YOUR PROJECT WILL BREAK package log package log provides a minimal interface for structured logging in ser

Go kit 111 Aug 2, 2022
HTTP request logger for Golang

Horus ?? Introduction Horus is a request logger and viewer for Go. It allows developers log and view http requests made to their web application. Inst

Michael Okoh 78 Jun 5, 2022
Simple Yet Powerful Logger

sypl sypl provides a Simple Yet Powerful Logger built on top of the Golang sypl. A sypl logger can have many Outputs, and each Output is responsible f

Sauce Labs 9 Apr 28, 2022