simplelog

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 3 Imported by: 10 modules, 25 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

simplelog

Overview

Simplelog is a simple encapsulation of the standard library "log" Because I need to be able to control the level of logging.

Install

go get github.com/vearne/simplelog

Use environment variables to set log level

optional value: debug | info | warn | error

export SIMPLE_LOG_LEVEL=info

Usage

package main

import (
	slog "github.com/vearne/simplelog"
	"os"
)

func main() {
	logFile := "/var/log/simple.log"
	f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		slog.Fatal("error opening file: %v", err)
	}
	slog.SetOutput(f)
	defer f.Close()
	// set log level
	slog.SetLevel(slog.DebugLevel)

	slog.Debug("log, %v", "debug")
	slog.Info("log, %v", "info")
	slog.Error("log, %v", "error")
	// Like log, Fatal() will terminal process
	slog.Fatal("log, %v", "fatal")
}

Output

2020/05/27 17:40:01 [debug] log, debug
2020/05/27 17:40:01 [info] log, info
2020/05/27 17:40:01 [error] log, error
2020/05/27 17:40:01 [fatal] log, fatal

Documentation

Index

Constants

View Source
const (
	DebugLevel = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

Variables

View Source
var (
	Level  = InfoLevel
	LogMap map[string]int
)

Functions

func Debug

func Debug(format string, v ...interface{})

func Error

func Error(format string, v ...interface{})

func Fatal

func Fatal(format string, v ...interface{})

func Info

func Info(format string, v ...interface{})

func SetLevel

func SetLevel(loglevel int)

func SetOutput

func SetOutput(w io.Writer)

func Warn

func Warn(format string, v ...interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

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