go_logger

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

README

go_logger 📘

A simple and flexible logger for Golang projects.

Installation 🚀

go get github.com/alirezadesh/go_logger

Usage 🛠️

package main

import (
	"github.com/alirezadesh/go_logger"
)

func main() {
  logger := go_logger.New(go_logger.Config{
	  LogToFile:   true,
	  LogToConsole: true,
	  FilePath:    "./logs/",
	  FileName:    "app.log",
	  LogLevel:    DebugLevel,
	  ConsoleEncoder: EncodeConfig{
		  Time:   true,
		  Caller: true,
		  Level:  true,
	  },
	  FileEncoder: EncodeConfig{
		  Time:   true,
		  Caller: true,
		  Level:  true,
	  },
  })
  
  logger.Info("Logger initialized!")
}

Log Levels 📊

  • DebugLevel
  • InfoLevel
  • WarnLevel
  • ErrorLevel
  • DPanicLevel
  • PanicLevel
  • FatalLevel

License 📝

GPL v3


Enjoy logging! 🚀

Documentation

Index

Constants

View Source
const (
	DebugLevel zapcore.Level = iota - 1
	InfoLevel
	WarnLevel
	ErrorLevel
	DPanicLevel
	PanicLevel
	FatalLevel

	InvalidLevel = _maxLevel + 1
)

Variables

This section is empty.

Functions

func Error added in v1.1.2

func Error(err error) zap.Field

func New

func New(config Config) *zap.Logger

Types

type Config

type Config struct {
	FilePath       string
	FileName       string
	LogLevel       zapcore.Level
	LogToFile      bool
	LogToConsole   bool
	ConsoleEncoder EncodeConfig
	FileEncoder    EncodeConfig
}

type EncodeConfig added in v1.1.4

type EncodeConfig struct {
	Time   bool
	Level  bool
	Caller bool
}

Jump to

Keyboard shortcuts

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