gomolwriter

package module
v0.0.0-...-1c115dd Latest Latest
Warning

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

Go to latest
Published: May 16, 2017 License: MIT Imports: 6 Imported by: 0 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-writer

GoDoc Build Status Code Coverage

gomol-writer is a logger for gomol to support logging to an io.Writer.

Installation

The recommended way to install is via http://gopkg.in

go get gopkg.in/aphistic/gomol-writer.v0
...
import "gopkg.in/aphistic/gomol-writer.v0"

gomol-writer can also be installed the standard way as well

go get github.com/aphistic/gomol-writer
...
import "github.com/aphistic/gomol-writer"

Examples

For brevity a lot of error checking has been omitted, be sure you do your checks!

This is a super basic example of adding an io.Writer logger to gomol and then logging a few messages:

package main

import (
	"os"
	"github.com/aphistic/gomol"
	gw "github.com/aphistic/gomol-writer"
)

func main() {
	// Add an io.Writer logger
	writerCfg := gw.NewWriterLoggerConfig()
	writerLogger, _ := gw.NewWriterLogger(os.Stdout, writerCfg)
	gomol.AddLogger(writerLogger)

	// 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)
	}
}

Documentation

Overview

Example

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

// Add an io.Writer logger
writerCfg := NewWriterLoggerConfig()
writerLogger, _ := NewWriterLogger(os.Stdout, writerCfg)
gomol.AddLogger(writerLogger)

// 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

This section is empty.

Functions

This section is empty.

Types

type WriterLogger

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

func NewWriterLogger

func NewWriterLogger(w io.Writer, cfg *WriterLoggerConfig) (*WriterLogger, error)

func (*WriterLogger) InitLogger

func (l *WriterLogger) InitLogger() error

func (*WriterLogger) IsInitialized

func (l *WriterLogger) IsInitialized() bool

func (*WriterLogger) Logm

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

func (*WriterLogger) SetBase

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

func (*WriterLogger) SetTemplate

func (l *WriterLogger) SetTemplate(tpl *gomol.Template) error

func (*WriterLogger) ShutdownLogger

func (l *WriterLogger) ShutdownLogger() error

type WriterLoggerConfig

type WriterLoggerConfig struct {
	/*
		The number of messages to be buffered before flushing them to
		the file.
	*/
	BufferSize int
}

func NewWriterLoggerConfig

func NewWriterLoggerConfig() *WriterLoggerConfig

Jump to

Keyboard shortcuts

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