zaplog

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 6 Imported by: 2

README

zaplog

Simple packaging for zap

Usage

package main

import (
	"fmt"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	zlog "github.com/vearne/zaplog"
	"go.uber.org/zap"
	"net/http"
	"sync/atomic"
	"time"
)

var ops uint64

func main() {
	zlog.InitLogger("/tmp/otel.log", "debug")
	go func() {
		for {
			atomic.AddUint64(&ops, 1)

			zlog.Debug("test debug", zap.Uint64("ops", atomic.LoadUint64(&ops)))
			zlog.Debug("test debug", zap.Uint64("ops", atomic.LoadUint64(&ops)))
			zlog.Debug("test debug", zap.Uint64("ops", atomic.LoadUint64(&ops)))

			zlog.Info("test info", zap.Uint64("ops", atomic.LoadUint64(&ops)))
			zlog.Info("test info", zap.Uint64("ops", atomic.LoadUint64(&ops)))

			zlog.Error("test error", zap.Uint64("ops", atomic.LoadUint64(&ops)))
			time.Sleep(200 * time.Millisecond)
		}

	}()

	http.Handle("/metrics", promhttp.Handler())
	fmt.Println("starting...")
	// http://localhost:9090/metrics
	http.ListenAndServe(":9090", nil)
}

Documentation

Index

Constants

View Source
const PromLabelLevel = "level" //http method

Variables

View Source
var (
	DefaultLogger *otelzap.Logger
)

Functions

func Debug

func Debug(msg string, fields ...zapcore.Field)

func DebugContext added in v0.0.2

func DebugContext(ctx context.Context, msg string, fields ...zapcore.Field)

func Error

func Error(msg string, fields ...zapcore.Field)

func ErrorContext added in v0.0.2

func ErrorContext(ctx context.Context, msg string, fields ...zapcore.Field)

func Fatal

func Fatal(msg string, fields ...zapcore.Field)

func FatalContext added in v0.0.2

func FatalContext(ctx context.Context, msg string, fields ...zapcore.Field)

func GetDefaultLogger

func GetDefaultLogger() *otelzap.Logger

func Info

func Info(msg string, fields ...zapcore.Field)

func InfoContext added in v0.0.2

func InfoContext(ctx context.Context, msg string, fields ...zapcore.Field)

func InitLogger

func InitLogger(logPath string, level string)

func Warn

func Warn(msg string, fields ...zapcore.Field)

func WarnContext added in v0.0.2

func WarnContext(ctx context.Context, msg string, fields ...zapcore.Field)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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