writer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package writer contains a series of writers that can write the log entries. A File can write logs to a given file. It will collapse the object if a json object is given, and uses them as the context of the log.

Index

Constants

This section is empty.

Variables

View Source
var MinimumDelay = 10 * time.Millisecond

MinimumDelay is the minimum time set for flush delays.

Functions

func WithBufWriter

func WithBufWriter(w *bufio.Writer) func(*File) error

WithBufWriter sets the buffered writer.

func WithFileLoc

func WithFileLoc(location string) func(*File) error

WithFileLoc opens a new file at location, or creates one if not exists. It returns error if it could not create or have write permission to the file.

func WithFlushDelay

func WithFlushDelay(delay time.Duration) func(*File) error

WithFlushDelay sets the delay time between flushes.

func WithLogger

func WithLogger(logger internal.FieldLogger) func(*File) error

WithLogger sets the delay time between flushes.

func WithWriter

func WithWriter(w writeCloseNamer) func(*File) error

WithWriter sets the output as the given writer. It wraps it in a buffer for better performance.

Types

type Distribute added in v0.1.0

type Distribute struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Distribute is a concurrent writer.

func NewDistribute added in v0.1.0

func NewDistribute(writers ...io.Writer) *Distribute

NewDistribute returns no errors. It dismissed the writers with nil values.

func (*Distribute) Write added in v0.1.0

func (c *Distribute) Write(p []byte) (int, error)

Write writes the input bytes into the writers concurrently. It returns an error if any of the writers fail to write.

type File

type File struct {
	sync.Mutex // guards against the buffer
	// contains filtered or unexported fields
}

File writs records log entries to a file. It buffers the writes to obtain better performance. It flushes the buffer every 1 seconds. It implements io.WriteCloser interface.

func NewFile

func NewFile(conf ...func(*File) error) (*File, error)

NewFile returns error if the file can not be created. It starts a goroutine that flushes the logs in intervals.

func (*File) Close

func (f *File) Close() error

Close closes the File.

func (*File) Flush

func (f *File) Flush() error

Flush flushes the underlying buffer.

func (*File) Logger added in v0.0.3

func (f *File) Logger() internal.FieldLogger

Logger returns the logger attached to the file

func (*File) Name

func (f *File) Name() string

Name returns the file location on disk.

func (*File) Write

func (f *File) Write(p []byte) (int, error)

Write writes the input bytes to the file. The write will not appear in the file unless the buffer is flushed. (see Flush())

Jump to

Keyboard shortcuts

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