htmllog

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2018 License: MIT Imports: 7 Imported by: 0

README

htmllog

a simple logger that safely produces an append-only, auto-scrolling-on-refresh HTML file.

documentation on godoc.org

(c)2016, http://ernestmicklei.com MIT License

Documentation

Overview

Package htmllog, a simple logger that produces an append-only, reloading HTML file

Features

usable by multiple go-routines
protection against printing recursive data structures in message
configureable log event function
configureable Html style
configureable limit on message

Example

h, err := htmllog.New("myapp.log")
h.Infof("just now is %v", time.Now())

Index

Constants

View Source
const (
	Debug = "debug"
	Info  = "info"
	Warn  = "warn"
	Error = "error"
	Fatal = "fatal"
)

Variables

View Source
var DefaultMaxMessageSize = 200

DefaultMaxMessageSize specifies the maxium length that a message can be.

View Source
var DefaultScrollToBottom = `` /* 252-byte string literal not displayed */
View Source
var DefaultStyle = `` /* 598-byte string literal not displayed */

Functions

func LimitedSprintf

func LimitedSprintf(limit int, format string, args ...interface{}) string

LimitedSprintf returns the result of fmt.Sprintf limited to a number of bytes. Use this function to protect against printing recursive structures.

func LogEvent

func LogEvent(hyper *Logger, logLevel, htmlEscapedMessage string)

LogEvent is the default implementation for an EventFunc and will write a timestamp, the log level, the (limited) message and a Html linebreak. This function is called in a protected region.

Types

type EventFunc

type EventFunc func(hyper *Logger, logLevel, htmlEscapedMessage string)

EventFunc is the signature for a custom definition how to write a log event.

type Logger

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

Logger provides a thread-safe access to the Html file for writing log events.

func New

func New(name string) (*Logger, error)

New creates a new logger and opens a new (or existing) file.

func NewOn

func NewOn(w io.Writer) (*Logger, error)

NewOn creates a new logger that uses a writer.

func (*Logger) Br

func (l *Logger) Br()

Br writes a Html linebreak. Must be called in a protected region.

func (*Logger) Configure

func (l *Logger) Configure(scroll string, style string, newLimit int, logFunc EventFunc)

Configure is to override default behavior of the logger.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf writes a message with Debug level

func (*Logger) Div

func (l *Logger) Div(cls string, block func())

Div writes the begin and end div tags around the block call. Must be called in a protected region.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf writes a message with Error level

func (*Logger) Event

func (l *Logger) Event(level string, format string, args ...interface{})

Event is the generic function for writing a log event

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf writes a message with Fatal level

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof writes a message with Info level

func (*Logger) Level

func (l *Logger) Level(level string)

Level writes the log level. Must be called in a protected region.

func (*Logger) Nbsp

func (l *Logger) Nbsp(s string, size int) string

Nbsp returns a new string of a fixed size, padded with Html non-breaking spaces.

func (*Logger) Raw

func (l *Logger) Raw(htmlEscapedMessage string)

Raw writes the message as is. Must be called in a protected region.

func (*Logger) Reset

func (l *Logger) Reset() error

func (*Logger) Timestamp

func (l *Logger) Timestamp()

Timestamp writes a formatted time (now). Must be called in a protected region.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf writes a message with Warn level

Jump to

Keyboard shortcuts

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