🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/CaledoniaProject/gopkg-lumberjack

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/CaledoniaProject/gopkg-lumberjack

v1.0.0
Source
Go
Version published
Created
Source

Introduction

If you have a multi-goroutine program where each goroutine uses Lumberjack for log rotation, the official repo may experience a memory leak. A fix was proposed years ago, but the pull request was never accepted. As a result, I'm creating my own repo to resolve this issue more quickly.

Usage

You can retrieve a rotating log handler like this, using the power of the Logrus library:

import (
    lumberjack "github.com/CaledoniaProject/gopkg-lumberjack"
)

func GetTTYFormatter() *logrus.TextFormatter {
	return &logrus.TextFormatter{
		TimestampFormat: "2006-01-02 15:04:05",
		DisableColors:   false,
		ForceColors:     true,
		FullTimestamp:   true,
		CallerPrettyfier: func(f *runtime.Frame) (string, string) {
			return "", fmt.Sprintf("[%s:%d]", path.Base(f.File), f.Line)
		},
	}
}

func GetRotatingFileLogger(filename string) (*logrus.Logger, *lumberjack.Logger) {
	lumberjack_logger := &lumberjack.Logger{
		Filename:   filename,
		MaxSize:    200,
		MaxBackups: 20,
		MaxAge:     7,
		Compress:   true,
	}
	logger := &logrus.Logger{
		Out:          lumberjack_logger,
		Formatter:    GetTTYFormatter(),
		ReportCaller: true,
		Level:        logrus.InfoLevel,
	}

	return logger, lumberjack_logger
}

FAQs

Package last updated on 20 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts