Git Product home page Git Product logo

gologger's Introduction

Gologger

A golang custom logger based on the loggrus logger: https://github.com/sirupsen/logrus

Then install it by using:

go get github.com/thiagohagy/gologger

Created to make possible to have logs separated by type and module, where you can enable/disable using the tags and logs types

You will have two types of structure, app and module logger

The module loggers will have its own tag

This package will log to your terminal and to a file(one file per day) under a /logs folder in your project root folder

You can configure a log rotate (30 days by default)

Creating a custom logger for your app:

To use it as inttended, you should create a appLogger, and use it to create your module loggers

On you main.go file:

// creating the main app logger
appLogger := gologger.NewMainLogger()

// creating a module logger
logger := gologger.NewModuleLogger("YOUR_MODULE_LOG_TAG", params.AppLogger)


// using your module logger
logger.Info("A informative log message", logrus.Fields{
    "data": someDataYouWantToShow
})

// Setting a custom config
appLogger.SetConfig(
    gologger.AppLoggerOptions{
        DisabledTags:      arrayOfDisabledTags,
        LogFileRotateDays: 10,
        LogLevel:          "info", //can be trace, debug, info, waning , fatal, panic
    },
)

You can use the log functions by calling:

  • appLogger.Log(logrus.InfoLevel, "YOUR_TAG", "Message", logrus.Fields{})
  • moduleLogger.Trace("Message", logrus.Fields{})
  • moduleLogger.Debug("Message", logrus.Fields{})
  • moduleLogger.Info("Message", logrus.Fields{})
  • moduleLogger.Warn("Message", logrus.Fields{})
  • moduleLogger.Fatal("Message", logrus.Fields{})
  • moduleLogger.Panic("Message", logrus.Fields{})

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.