itrlog

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 8 Imported by: 9

README

ITRLog

The simplified usage of Zap and Lumberjack logging systems in Go for easier usage of the library.

Installation

go get -u github.com/itrepablik/itrlog

Usage

This is how you can use the simplified initializations for Zap and Lumberjack logging libraries.

package main

import (
	"github.com/itrepablik/itrlog"
)

func init() {
	// Custom settings to initialize the itrlog.
	itrlog.SetLogInit(50, 90, "logs", "test_log_")
}

func main() {
	// Basic logging message
	itrlog.Info("basic info log output...")
	itrlog.Error("basic error log output...")
	itrlog.Warn("basic warning log output...")
	itrlog.Debug("basic debug log output...")
	
	// Structured context as loosely typed key-value pairs.
	itrlog.Infow("New User", "username", "admin", "email", "email@site.com", "log_time", time.Now().Format(itrlog.LogTimeFormat))
	itrlog.Errorw("New User", "username", "admin", "email", "email@site.com", "log_time", time.Now().Format(itrlog.LogTimeFormat))
	itrlog.Warnw("New User", "username", "admin", "email", "email@site.com", "log_time", time.Now().Format(itrlog.LogTimeFormat))
	itrlog.Debugw("New User", "username", "admin", "email", "email@site.com", "log_time", time.Now().Format(itrlog.LogTimeFormat))
}

It will auto-create the logs folder in the root directory of your project, but, of course, it's up to you which directory to point your log files and the test_log_ is the initial log filename. The logging output it's a JSON format for easy integration with any of your existing software to keep track of the logs information.

Subscribe to Maharlikans Code Youtube Channel:

Please consider subscribing to my Youtube Channel to recognize my work on this package. Thank you for your support! https://www.youtube.com/channel/UCdAVUmldU9Jn2VntuQChHqQ/

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.

Documentation

Overview

Package itrlog is the custom logger for Go using Zap and Lumberjack libraries.

Index

Constants

View Source
const LogTimeFormat string = "Jan-02-2006 03:04:05 PM"

LogTimeFormat formats the event timestamp.

Variables

This section is empty.

Functions

func DPanic

func DPanic(args ...interface{})

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)

func DPanicf

func DPanicf(template string, args ...interface{})

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)

func DPanicw

func DPanicw(msg string, keysAndValues ...interface{})

DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.

func Debug

func Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

func Debugf

func Debugf(template string, args ...interface{})

Debugf uses fmt.Sprintf to log a templated message.

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

When debug-level logging is disabled, this is much faster than

s.With(keysAndValues).Debug(msg)

func Error

func Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func Errorf

func Errorf(template string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func Fatal

func Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func Fatalf

func Fatalf(template string, args ...interface{})

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func Fatalw

func Fatalw(msg string, keysAndValues ...interface{})

Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.

func Info

func Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func Infof

func Infof(template string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func Infow

func Infow(msg string, keysAndValues ...interface{})

Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func Panic

func Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func Panicf

func Panicf(template string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func Panicw

func Panicw(msg string, keysAndValues ...interface{})

Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.

func Warn

func Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func Warnf

func Warnf(template string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

Types

type ITRLogger

type ITRLogger struct {
	MaxSizeInMB, MaxAgeInDays int
	LogFolderName, LogInitial string
	Sugar                     *zap.SugaredLogger
	Base                      *zap.Logger
	// contains filtered or unexported fields
}

ITRLogger contains the necessary information to initialize the required parameters for the itrlog package.

func InitLog

func InitLog(maxSizeInMB, maxAgeInDays int, logFolderName, logInitial string) *ITRLogger

InitLog initialize the zap and lumberjack logger library. Example log file: logs/app_name_2020-02-28.log

func SetLogInit

func SetLogInit(maxSizeInMB, maxAgeInDays int, logFolderName, logFileName string) *ITRLogger

SetLogInit sets the custom log requirement to initialize the itr logger.

Jump to

Keyboard shortcuts

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