logging

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

Overview

This is a simple go logger that can be used to log logs of different package into different file.

The simplest way to use this package is to import and then get logger by name. Include log_config.json file in either default project-directory or project-directory/resources

package main

import (
	"github.com/zapr-oss/logging_go"
	"github.com/sirupsen/logrus"
	)

var log = logging.GetLogger("handler")

func main() {
        log.WithFields(logrus.Fields{
            "name":       "John",
            "id":         10}).
            Errorln("error getting data")
}

This will create a file name handler.log in the directory given in log_config.json. If you want to use the same file for logging all logs, log object can be passed to all functions and packages.

{
  "path": "/home/ubuntu/content-inventory-scripts/ott_content_merger/content_merger/logs/",
  "level": "info",  //getting log level
  "maxSizeInMb": 50,
  "maxBackups": 5,
  "maxAgeInDays": 30,
  "gZipCompress": true, // gzip compress the backups
  "isDifferentErrorFile": true, // will log error logs to file with .err extention
  "formatter": "text", //setting formatter. (text/json)
  "env": "prod", //this is used to set local/dev env to always use debug logs.
  "shouldSetCaller": true //used to print the line at which logging happened
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogger

func GetLogger(name string) *log.Logger

Types

type LogConfig

type LogConfig struct {
	Path            string `json:"path"`
	Level           string `json:"level"`
	MaxSizeInMb     int    `json:"maxSizeInMb"`
	MaxBackups      int    `json:"maxBackups"`
	MaxAgeInDays    int    `json:"maxAgeInDays"`
	GZipCompress    bool   `json:"gZipCompress"`
	IDEF            bool   `json:"isDifferentErrorFile"`
	Formatter       string `json:"formatter"`
	Env             string `json:"env"`
	ShouldSetCaller bool   `json:"shouldSetCaller"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL