netlog

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

README

netlog

logging package

How to use?

  1. Determine the log output method.
  • output to any log file
    • ex. /var/log/example.log
    var logOutput string
    logOutput = "file:///var/log/example.log"
    
  • output via syslog in local
    • ex. facility: sys, tag: example
    var logOutput string
    logOutput = "net:///?facility=sys&tag=example"
    
  • output via syslog with TCP connection (Windows OS is not supported)
    • ex. facility: sys, tag: example
    var logOutput string
    logOutput = tcp://localhost:601/?facility=sys&tag=example"
    
  1. Initialize using log output destination.
    import (
    	"log"
    )
    
    func main() {
    	if logOutput != "" {
    		if err := netlog.SetOutputURL(logOutput); err != nil {
    			log.Fatal("log output destination:", err)
    		}
    	}
    }
    
  2. Output logs.
    import (
    	"github.com/lufia/netlog"
    )
    
    func example() {
        // netlog.SetOutputURL(logOutput, debugMode)
        netlog.Debug("output if the debug flag is enabled at initialization")
    
        netlog.Info("this is info message")
        netlog.Warning("this is warning message")
        netlog.Err("this is error message")
        netlog.Crit("this is critical error message. process AbEnd here")
    }
    

Log level

func Level (linux/unix) Msg ID (windows)
netlog.Crit() LOG_CRIT 4001
netlog.Err() LOG_ERR 3001
netlog.Warning() LOG_WARNING 2001
netlog.Info() LOG_INFO 1001
netlog.Debug() LOG_DEBUG 1001

Documentation

Index

Constants

View Source
const (
	LogSystem      = facilitySystem
	LogApplication = facilityApplication
	LogService     = facilityService
	LogSecurity    = facilitySecurity
)

Variables

This section is empty.

Functions

func Crit

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

Crit outputs critical level log output. It is usually used to output critical conditions. When this method is executed, the process abends after outputting the log. This log level need be treated as an anomaly.

func Debug

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

Debug outputs debug level log output. It is usually used to output detailed debug information. If debug status is not enabled, no output is generated. This log level need not be treated as an anomaly. The debug status can be set from SetDebug.

func Err

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

Err outputs error level log output. It is usually used to output execution-time errors that do not require immediate action but should typically be logged and monitored. This log level need be treated as an anomaly.

func Info

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

Info outputs information level log output. It is usually used to output interesting events. This log level need not be treated as an anomaly.

func SetDebug added in v1.1.0

func SetDebug(state bool)

SetDebug can enable/disable debug mode.

func SetOutputURL

func SetOutputURL(s string, debug ...bool) (err error)

SetOutputURL is to set output for netlog.

func Warning

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

Warning outputs warning level log output. It is usually used to output exceptional occurrences that are not errors. This log level need not be treated as an anomaly.

Types

type Facility

type Facility int

type Logger

type Logger interface {
	// contains filtered or unexported methods
}
var (
	DefaultLogger Logger = &consoleLogger{w: os.Stderr}
)

Jump to

Keyboard shortcuts

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