spinlog

package module
v0.0.0-...-198bf16 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2014 License: BSD-2-Clause Imports: 8 Imported by: 0

README

spinlog

spinlog is a simple API and command-line tool for rotating logs.

Installing

You can install the spinlog API as follows:

go get github.com/unixpickle/spinlog

Once you have this library, you may also wish to use the spinlog utility command. You can install it using this command:

go install github.com/unixpickle/spinlog/spinlog

Now you can run the spinlog command. For help and usage, see

spinlog -h

License

spinlog is licensed under the BSD 2-clause license. See LICENSE.

Copyright (c) 2014, Alex Nichol.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadConfig = errors.New("Bad configuration.")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	LogDir   LogDir `json:"log_dir"`
	MaxCount int    `json:"max_count"`
	MaxSize  int64  `json:"max_size"`
	SetPerm  bool   `json:"set_perm"`
	Perm     int    `json:"perm"`
	SetOwner bool   `json:"set_owner"`
	GID      int    `json:"gid"`
	UID      int    `json:"uid"`
}

type LineConfig

type LineConfig struct {
	Config
	MaxLineSize int `json:"max_line_size"`
}

type LineLog

type LineLog struct {
	*Log
	// contains filtered or unexported fields
}

func NewLineLog

func NewLineLog(c LineConfig) (*LineLog, error)

func (*LineLog) Close

func (l *LineLog) Close() error

func (*LineLog) Write

func (l *LineLog) Write(p []byte) (int, error)

type Log

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

func NewLog

func NewLog(c Config) (*Log, error)

func (*Log) Close

func (r *Log) Close() error

func (*Log) Write

func (r *Log) Write(p []byte) (int, error)

type LogDir

type LogDir struct {
	Directory string `json:"directory"`
	Prefix    string `json:"prefix"`
}

LogDir stores a log directory and a file prefix.

func NewLogDir

func NewLogDir(dir, prefix string) LogDir

NewLogDir creates a new LogDir instance given a directory and prefix.

func (LogDir) FilePath

func (l LogDir) FilePath(index int) string

FilePath returns the path to a log file with a given index.

func (LogDir) List

func (l LogDir) List() ([]int, error)

List reads the directory to find numerically labeled log files. For example, if the prefix is "foo" and the directory contains files called ["foo.0", "foo.24", "foobar", "foo.3"], this will return [0, 3, 24]. The result is always sorted in ascending order. The result will never contain duplicate numbers. An error will be returned if the directory listing cannot be read.

func (LogDir) Rotate

func (l LogDir) Rotate(max int) error

Rotate perfroms manual log rotation on a given directory. The max argument determines how many log files should be allowed to exist at once, including the 0 file which will not exist after this call. For example, if the prefix is "foo", max is 3, and the directory contains files called ["foo.0", "foo.1", "foo.2", "foo.3", "foo.4", "foobar"], this will delete "foo.2", "foo.3", and "foo.4". It will rename "foo.1" to "foo.2" and "foo.0" to "foo.1". Usually, you do not need to use this method directly. Log and LineLog run it for you. An error will be returned if the directory cannot be read, if a file cannot be removed, or if a file cannot be renamed.

type Router

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

Router is an io.Writer whose output stream can be modified dynamically.

func NewRouter

func NewRouter() *Router

NewRouter creates a new router with no target.

func (*Router) GetTarget

func (r *Router) GetTarget() *io.Writer

GetTarget returns the router's current target.

func (*Router) SetTarget

func (r *Router) SetTarget(writer io.Writer)

SetTarget sets the router's current target.

func (*Router) Write

func (r *Router) Write(p []byte) (n int, err error)

Write writes the bytes to the router's current target. If the router has no target, (len(p), nil) is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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