jsonstream

package module
v0.0.0-...-171e0a2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gomol-jsonfile

A logger for Gomol to log to a file on the filesystem using JSON objects.

Documentation

Overview

Example

Code for the README example to make sure it still builds!

// Open a file to write JSON logs to
logFile, _ := os.Open("my/logs/run.log")
defer logFile.Close()

// Add an io.Writer logger
jsCfg := NewConfig(logFile)
jsLogger, _ := NewLogger(jsCfg)
gomol.AddLogger(jsLogger)

// Set some global attrs that will be added to all
// messages automatically
gomol.SetAttr("facility", "gomol.example")
gomol.SetAttr("another_attr", 1234)

// Initialize the loggers
gomol.InitLoggers()
defer gomol.ShutdownLoggers()

// Log some debug messages with message-level attrs
// that will be sent only with that message
for idx := 1; idx <= 10; idx++ {
	gomol.Dbgm(
		gomol.NewAttrs().
			SetAttr("msg_attr1", 4321),
		"Test message %v", idx)
}

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownType = errors.New("unknown message type")
)

Functions

func WithHeaders

func WithHeaders(headers map[string]interface{}) loggerConfig

Types

type Config

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

func NewConfig

func NewConfig(w io.Writer, configs ...loggerConfig) *Config

type HeaderMsg

type HeaderMsg struct {
	Timestamp time.Time              `json:"time"`
	Headers   map[string]interface{} `json:"headers"`
}

type LogMsg

type LogMsg struct {
	Timestamp time.Time              `json:"time"`
	Msg       string                 `json:"msg"`
	Level     gomol.LogLevel         `json:"level"`
	Attrs     map[string]interface{} `json:"attrs"`
}

type Logger

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

func NewLogger

func NewLogger(cfg *Config) (*Logger, error)

func (*Logger) Flush

func (l *Logger) Flush() error

func (*Logger) InitLogger

func (l *Logger) InitLogger() error

func (*Logger) IsInitialized

func (l *Logger) IsInitialized() bool

func (*Logger) Logm

func (l *Logger) Logm(timestamp time.Time, level gomol.LogLevel, attrs map[string]interface{}, msg string) error

func (*Logger) SetBase

func (l *Logger) SetBase(base *gomol.Base)

func (*Logger) ShutdownLogger

func (l *Logger) ShutdownLogger() error

type Message

type Message interface{}

type Reader

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

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) Next

func (r *Reader) Next() (Message, error)

Jump to

Keyboard shortcuts

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