zlog

package module
v1.0.1-pro Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: MIT Imports: 7 Imported by: 1

README

zlog

Uber based zaplog carries out simple and crude encapsulation, allowing users to quickly develop log modules

Install

go get -u github.com/miajio/zlog

package zlog_test

import (
	"testing"

	"github.com/miajio/zlog"
)

func TestLoggerFile(t *testing.T) {
    // set log param
	l := zlog.Logger{
		Path:       "./log",
		MaxSize:    256,
		MaxBackups: 10,
		MaxAge:     7,
		Compress:   false,
	}
    // set log level func
	lv := zlog.LogMap{
		"debug": zlog.DebufLevel,
		"info":  zlog.InfoLevel,
		"error": zlog.ErrorLevel,
	}
    // init logger
	l.Generate(lv)
    // info
	l.Log.Info("hello")
}

Documentation

Overview

Package zlog implements a log tool called zlog.

Index

Constants

This section is empty.

Variables

View Source
var (
	DebufLevel = func(level zapcore.Level) bool {
		return level == zap.DebugLevel
	}

	InfoLevel = func(level zapcore.Level) bool {
		return level == zap.InfoLevel
	}

	ErrorLevel = func(level zapcore.Level) bool {
		return level == zap.ErrorLevel
	}
)

default log level

Functions

func GetLogFilePath

func GetLogFilePath(filePath, fileName string) string

logFile logger file out path

Types

type Level

type Level func(zapcore.Level) bool

Level log level

type LogMap

type LogMap map[string]Level

LogMap log level map map key is file name value is log print level func

type Logger

type Logger struct {
	Path       string `json:"path" toml:"toml"`             // log file path
	MaxSize    int    `json:"maxSize" toml:"maxSize"`       // log file max size
	MaxBackups int    `json:"maxBackups" toml:"maxBackups"` // log file max backups
	MaxAge     int    `json:"maxAge" toml:"maxAge"`         // log file max save day
	Compress   bool   `json:"compress" toml:"compress"`     // log file whether to compress

	Log *zap.SugaredLogger // zap log object
	// contains filtered or unexported fields
}

Logger

func (*Logger) Generate

func (log *Logger) Generate(logMap LogMap)

Generate

type LoggerInterface

type LoggerInterface interface {
	Generate(LogMap) // Generate logger core
}

LoggerInterface

Jump to

Keyboard shortcuts

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