renderer

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Level

func Level(info event.Info, w io.Writer) (int, error)

Level writes info.Level to w

func LoggerName

func LoggerName(info event.Info, w io.Writer) (int, error)

LoggerName writes info.Source.LoggerName() to w

func Message

func Message(info event.Info, w io.Writer) (int, error)

Message writes info.Message to w

func RegisterRenderer

func RegisterRenderer(name string, r LayoutRenderer)

RegisterRenderer takes a name and an instance of a LayoutRenderer and registers it so that the name can be used in layout templates.

If r also implements LayoutRendererWithParameters then r.CreateLayoutRenderer will be called to create a new instance of the LayoutRenderer if the template specifies any parameters

Types

type BaseDir

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

BaseDir renders the directory of the executable relative to the current working directory and is typically useful for specifying where to save log files

Example:

"filename": "${basedir}/logs/debug.log"

func (*BaseDir) IsDynamic

func (*BaseDir) IsDynamic() bool

IsDynamic returns false

func (*BaseDir) Write

func (bd *BaseDir) Write(info event.Info, w io.Writer) (int, error)

Write writes the directory of the executable to w

type DateTime

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

func (*DateTime) CreateLayoutRenderer

func (dt *DateTime) CreateLayoutRenderer(parameters map[string]string) (LayoutRenderer, error)

func (*DateTime) IsDynamic

func (*DateTime) IsDynamic() bool

func (*DateTime) Write

func (dt *DateTime) Write(info event.Info, w io.Writer) (int, error)

type LayoutFunc

type LayoutFunc func(event.Info, io.Writer) (int, error)

The LayoutFunc type is an adapter to allow the use of ordinary functions as layout renderers. If f is a function with the appropriate signature, LayoutFunc(f) is a LayoutRenderer that calls f.

func (LayoutFunc) IsDynamic

func (f LayoutFunc) IsDynamic() bool

IsDynamic returns true

func (LayoutFunc) Write

func (f LayoutFunc) Write(info event.Info, w io.Writer) (int, error)

Write calls f(info, w)

type LayoutRenderer

type LayoutRenderer interface {
	// Write takes the information in info and writes it to w.  The return values are
	// the number of bytes written and any error that occurred.
	Write(info event.Info, w io.Writer) (int, error)
	// IsDynamic returns false if the data written by Write is static throughout the
	// course of the applications lifetime. It returns true otherwise.
	IsDynamic() bool
}

LayoutRenderer is the interface that wraps a layout renderer.

When creating custom renderers, this is the interface that needs to be implemented.

type LayoutRendererWithParameters

type LayoutRendererWithParameters interface {
	CreateLayoutRenderer(parameters map[string]string) (LayoutRenderer, error)
}

LayoutRendererWithParameters is the interface which wraps a LayoutRenderer factory such that parameters can be specified in the layout

Custom LayoutRenderers will typically also implement this interface if its behaviour can be customized

type Renderer

type Renderer interface {
	// Render returns a string rendered from info based on the template provided to New
	Render(info event.Info) string
}

Renderer is the interface that wraps a specific template

func New

func New(template string) (Renderer, error)

New returns a Renderer that conforms to the template provided using registered LayoutRenderers and an error if there was an error in the template

Jump to

Keyboard shortcuts

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