gomolconsole

package module
v0.0.0-...-9fa1742 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2018 License: MIT Imports: 7 Imported by: 0

README

gomol-console

GoDoc Build Status Code Coverage

gomol-console is a logger for gomol to support logging to the console.

Installation

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

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

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

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

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 a console logger to gomol and then logging a few messages:

package main

import (
	"github.com/aphistic/gomol"
	gc "github.com/aphistic/gomol-console"
)

func main() {
	// Add an io.Writer logger
	consoleCfg := gc.NewConsoleLoggerConfig()
	consoleLogger, _ := gc.NewConsoleLogger(consoleCfg)
	gomol.AddLogger(consoleLogger)

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

Package gomolconsole implements a console logger for gomol.

Example

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

// Add an io.Writer logger
consoleCfg := NewConsoleLoggerConfig()
consoleLogger, _ := NewConsoleLogger(consoleCfg)
gomol.AddLogger(consoleLogger)

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTemplateDefault

func NewTemplateDefault() *gomol.Template

NewTemplateDefault will create a new default logging template.

Example output:

[INFO] This is my message

func NewTemplateFull

func NewTemplateFull() *gomol.Template

NewTemplateFull will create a new logging template including the current timestamp as well as any attributes included with the message.

Example output:

2006-01-02 15:04:05.000 [INFO] This is my message
   attr1: 1234
   attr2: value2

func NewTemplateTimestamped

func NewTemplateTimestamped() *gomol.Template

NewTemplateTimestamped will create a new logging template including the current timestamp.

Example output:

2006-01-02 15:04:05.000 [INFO] This is my message

Types

type ConsoleLogger

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

func NewConsoleLogger

func NewConsoleLogger(config *ConsoleLoggerConfig) (*ConsoleLogger, error)

func (*ConsoleLogger) InitLogger

func (l *ConsoleLogger) InitLogger() error

func (*ConsoleLogger) IsInitialized

func (l *ConsoleLogger) IsInitialized() bool

func (*ConsoleLogger) Logm

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

func (*ConsoleLogger) SetBase

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

func (*ConsoleLogger) SetTemplate

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

func (*ConsoleLogger) ShutdownLogger

func (l *ConsoleLogger) ShutdownLogger() error

type ConsoleLoggerConfig

type ConsoleLoggerConfig struct {
	// Colorize specifies whether the output will include ANSI colors or not. Defaults to true
	Colorize bool

	// Writer is the io.Writer to be used if not overridden in other options. Defaults to os.Stdout
	Writer io.Writer

	// DebugWriter is the io.Writer debug messages will be written to. Defaults to Writer
	DebugWriter io.Writer
	// InfoWriter is the io.Writer info messages will be written to. Defaults to Writer
	InfoWriter io.Writer
	// WarningWriter is the io.Writer warning messages will be written to. Defaults to Writer
	WarningWriter io.Writer
	// ErrorWriter is the io.Writer error messages will be written to. Defaults to Writer
	ErrorWriter io.Writer
	// FatalWriter is the io.Writer fatal messages will be written to. Defaults to Writer
	FatalWriter io.Writer
}

func NewConsoleLoggerConfig

func NewConsoleLoggerConfig() *ConsoleLoggerConfig

Jump to

Keyboard shortcuts

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