slog

package module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2018 License: MIT Imports: 5 Imported by: 6

README

slog Build Status

This package is a very simplistic logger for Go-based server software. It logs informational and error messages with or without timestamps in an Apache-like style. There are no external dependencies - only Go internals are needed to build it.

Installing

Run this from a shell:

go get -u github.com/Urethramancer/slog

Example

package main

import (
	"io/ioutil"
	"os"
	"time"

	"github.com/Urethramancer/slog"
)

func main() {
	file, err := ioutil.TempFile(os.TempDir(), "slog")
	if err != nil {
		slog.Error("Error: %s", err.Error())
		return
	}

	slog.Msg("Logging errors to %s", file.Name())
	slog.SetErrorFile(file)
	slog.TError("This message goes to a file named %s.", file.Name())
	slog.TMsg("Logged an error to %s.", file.Name())
	slog.CloseErrorFile(file)
}

Licence

MIT. See the file LICENSE if unfamiliar.

Documentation

Overview

Package slog is a simple logger, using a worker goroutine to print the output strings and optionally log them with Apache-style timestamps, optionally using configurable channels instead of os.Stdout and os.Stderr.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseErrorFile added in v0.7.0

func CloseErrorFile() error

CloseErrorFile and set the error output back to stderr.

func CloseMsgFile added in v0.7.0

func CloseMsgFile() error

CloseMsgFile and set the message output back to stdout.

func CloseWarnFile added in v0.7.0

func CloseWarnFile() error

CloseWarnFile and set the warning output back to stderr.

func Error

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

Error sends a log message to the error output.

func Msg

func Msg(f string, v ...interface{})

Msg sends a log message to the information output.

func SetErrorFile

func SetErrorFile(file *os.File)

SetErrorFile lets you set the output for error messages. The default is os.Stderr. If a new file is supplied, the user is responsible for closing it.

func SetMsgFile

func SetMsgFile(file *os.File)

SetMsgFile lets you set the output for informational messages. The default is os.Stdout. If a new file is supplied, the user is responsible for closing it.

func SetWarnFile added in v0.4.0

func SetWarnFile(file *os.File)

SetWarnFile lets you set the output for warning messages. The default is os.Stderr. If a new file is supplied, the user is responsible for closing it.

func TError

func TError(f string, v ...interface{})

TError sends a log message to the error output with timestamps.

func TMsg

func TMsg(f string, v ...interface{})

TMsg sends a log message to the information output with timestamps.

func TWarn added in v0.4.0

func TWarn(f string, v ...interface{})

TWarn sends a log message to the information output with timestamps.

func Warn added in v0.4.0

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

Warn sends a log message to the warning output.

Types

This section is empty.

Jump to

Keyboard shortcuts

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