logit

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 5 Imported by: 2

README

Logit

Logger created in Golang. Runs as a separate goroutine.

Usage

Create a Loggit Object in your code, this will need to be a global variable so all functions can access it

var ThisLog *Logit.Logger

Logit accepts items that implement the "io.WriteCloser" to be valid Loggers. Included are funtions to Log to a File and the Terminal.

FileLog, err := Logit.OpenFile("/path/to/log/file")
TermLog := Logit.TermLog()

Somewhere in your code, you need to Start the Logging goroutine.

ThisLog, err = Logit.StartLogger(FileLog)
ThatLog, err = Logit.StartLogger(TermLog)

This will start a goroutine that has the file open.

Logit then uses Channels to push strings into this goroutine, writing them to the Log. Format a string to your liking, and simply pass it into the Log object that you created.

ThisLog.Log("string!")

Using the above will produce the following example output in the log:

09:15:15.918788110:  string!

On shutdown of your application, you will want to run the "Quit" function on your Logit Object to ensure all is closed and the goroutines are stopped.

ThisLog.Quit()
ThatLog.Quit()

Features

Able to handle concurrency. As long as your goroutine has access to a valid Logit Object, you are able to use the Log function safely. By pushing a string onto the channel, Logit will append it to the log when it can.

TODO

As of now if the log file is removed during runtime Logit will not complain, and all will continue to work without a hitch except logging. This is not ideal of course.

Documentation

Index

Constants

View Source
const (
	MSG = iota
	WARN
	DEBUG
	ERROR
	PANIC
)

Variables

This section is empty.

Functions

func Error

func Error(stat Status, call string, m string) *errors

func Errorf

func Errorf(stat Status, call string, format string, a ...interface{}) *errors

func OpenFile

func OpenFile(f string) (io.WriteCloser, error)

func TermLog

func TermLog() io.WriteCloser

Types

type Logger

type Logger struct {
	TimeFormat string
	// contains filtered or unexported fields
}

Logger Logic

func Start

func Start(f io.WriteCloser) (*Logger, error)

func (*Logger) Log

func (l *Logger) Log(e Status, a ...string)

func (*Logger) LogError

func (l *Logger) LogError(o Status, e error)

func (*Logger) Logf

func (l *Logger) Logf(e Status, format string, a ...interface{})

func (*Logger) Quit

func (l *Logger) Quit()

type Status

type Status int

func (Status) String

func (s Status) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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