zapper

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

README

zapper Go Reference

zapper is zap but customized with multi core and sentry support, zapper make easiest usage with zap logger.

Cores
  • Console Writer
  • Sentry Core
  • File Writer
  • Json Core

Install

$ go get -u github.com/GoFarsi/zapper

Example

  • Console writer core
package main

import (
	"github.com/GoFarsi/zapper"
	"log"
)

func main() {
	z := zapper.New(false, zapper.WithTimeFormat(zapper.RFC3339NANO))
	if err := z.NewCore(zapper.ConsoleWriterCore(true)); err != nil {
		log.Fatal(err)
	}

	z.Info("test info")
	z.Debug("debug level")
}
  • Sentry Core
package main

import (
	"github.com/GoFarsi/zapper"
	"log"
	"os"
)

func main() {
	z := zapper.New(false)
	if err := z.NewCore(zapper.SentryCore(os.Getenv("DSN"), "test", nil)); err != nil {
		log.Fatal(err)
	}

	err(z)
}

func err(z zapper.Zapper) {
	z.Error("test error new")
}

Contributing

  1. Fork zapper repository
  2. Clone forked project
  3. create new branch from main
  4. change things in new branch
  5. then send Pull Request from your changes in new branch

Documentation

Index

Constants

View Source
const (
	CONSOLE coreType = iota
	SENTRY
	FILE
	JSON
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Caller

type Caller interface {
	Debug(...any)
	DebugF(string, ...any)
	DebugW(string, ...any)

	Info(...any)
	InfoF(string, ...any)
	InfoW(string, ...any)

	Warn(...any)
	WarnF(string, ...any)
	WarnW(string, ...any)

	Error(...any)
	ErrorF(string, ...any)
	ErrorW(string, ...any)

	DPanic(...any)
	DPanicF(string, ...any)
	DPanicW(string, ...any)

	Panic(...any)
	PanicF(string, ...any)
	PanicW(string, ...any)

	Fatal(...any)
	FatalF(string, ...any)
	FatalW(string, ...any)
}

type Core

type Core interface {
	// contains filtered or unexported methods
}

Core zapper base abstract

func ConsoleWriterCore

func ConsoleWriterCore(colorable bool) Core

ConsoleWriterCore create console writer for zapper to show log in console

func SentryCore

func SentryCore(dsn string, serverName string, cfg *SentryConfig) Core

SentryCore send log into sentry service

type Err

type Err struct {
	Message string
	Params  []any
}

func NewError

func NewError(msg string, params ...any) *Err

func (*Err) Error

func (e *Err) Error() string

type Level

type Level zapcore.Level

Level zapper levels

const (
	Debug  Level = iota - 1 // Debug logs are typically voluminous, and are usually disabled in production
	Info                    // Info is the default logging priority
	Warn                    // Warn logs are more important than Info, but don't need individual human review
	Error                   // Error logs are high-priority. If an application is running smoothly, it shouldn't generate any error-level logs
	DPanic                  // DPanic logs are particularly important errors. In development the logger panics after writing the message
	Panic                   // Panic logs a message, then panics
	Fatal                   // Fatal logs a message, then calls os.Exit(1)
)

func (Level) String

func (i Level) String() string

type Option

type Option func(*Zap)

func WithCustomStackTraceLevel

func WithCustomStackTraceLevel(level Level) Option

WithCustomStackTraceLevel set custom level for show stacktrace, min level warn

func WithDebugLevel

func WithDebugLevel() Option

WithDebugLevel enable debug level for logging

func WithTimeFormat

func WithTimeFormat(format TimeFormat) Option

WithTimeFormat set custom time format for zapper logs

type Rotation

type Rotation struct {
	MaxAge   int
	FileSize int
	Compress bool
}

Rotation config log file rotation in log path

type SentryConfig

type SentryConfig struct {
	AttachStacktrace  bool
	Debug             bool
	EnableTracing     bool
	Environment       string
	Dist              string
	EnableBreadcrumbs bool
	BreadcrumbLevel   Level
	MaxBreadcrumbs    int
	MaxSpans          int
	Tags              map[string]string
	MinLevel          Level
	FlushTimeout      time.Duration
}

SentryConfig for sentry core set custom configs

type TimeFormat

type TimeFormat int

TimeFormat set custom time format for zap log

const (
	ISO8601     TimeFormat = iota // ISO8601 serializes a time.Time to an ISO8601-formatted string with millisecond precision
	RFC3339                       // RFC3339 serializes a time.Time to an RFC3339-formatted string
	RFC3339NANO                   // RFC3339NANO  serializes a time.Time to an RFC3339-formatted string with nanosecond precision
)

func (TimeFormat) String

func (i TimeFormat) String() string

type Zap

type Zap struct {
	// contains filtered or unexported fields
}

func (*Zap) DPanic

func (z *Zap) DPanic(args ...any)

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

func (*Zap) DPanicF

func (z *Zap) DPanicF(message string, args ...any)

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

func (*Zap) DPanicW

func (z *Zap) DPanicW(message string, keyAndValues ...any)

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 (*Zap) Debug

func (z *Zap) Debug(args ...any)

Debug uses fmt.Sprint to construct and log a message

func (*Zap) DebugF

func (z *Zap) DebugF(message string, args ...any)

DebugF uses fmt.Sprintf to log a templated message

func (*Zap) DebugW

func (z *Zap) DebugW(message string, keyAndValues ...any)

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 (*Zap) Error

func (z *Zap) Error(args ...any)

Error uses fmt.Sprint to construct and log a message

func (*Zap) ErrorF

func (z *Zap) ErrorF(message string, args ...any)

ErrorF uses fmt.Sprintf to log a templated message

func (*Zap) ErrorW

func (z *Zap) ErrorW(message string, keyAndValues ...any)

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

func (*Zap) Fatal

func (z *Zap) Fatal(args ...any)

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

func (*Zap) FatalF

func (z *Zap) FatalF(message string, args ...any)

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

func (*Zap) FatalW

func (z *Zap) FatalW(message string, keyAndValues ...any)

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 (*Zap) Info

func (z *Zap) Info(args ...any)

Info uses fmt.Sprint to construct and log a message

func (*Zap) InfoF

func (z *Zap) InfoF(message string, args ...any)

InfoF uses fmt.Sprintf to log a templated message

func (*Zap) InfoW

func (z *Zap) InfoW(message string, keyAndValues ...any)

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

func (*Zap) NewCore

func (z *Zap) NewCore(cores ...Core) error

NewCore create cores for zapper

func (*Zap) Panic

func (z *Zap) Panic(args ...any)

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

func (*Zap) PanicF

func (z *Zap) PanicF(message string, args ...any)

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

func (*Zap) PanicW

func (z *Zap) PanicW(message string, keyAndValues ...any)

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

func (*Zap) Warn

func (z *Zap) Warn(args ...any)

Warn uses fmt.Sprint to construct and log a message

func (*Zap) WarnF

func (z *Zap) WarnF(message string, args ...any)

WarnF uses fmt.Sprintf to log a templated message

func (*Zap) WarnW

func (z *Zap) WarnW(message string, keyAndValues ...any)

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

type Zapper

type Zapper interface {
	Caller

	NewCore(...Core) error
}

func New

func New(development bool, opts ...Option) Zapper

New create new Zap object

Directories

Path Synopsis
_example
console command
sentry command

Jump to

Keyboard shortcuts

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