dummylog

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 9 Imported by: 0

README

Dummylog

Dummylog - prints silly messages to stdout or file in text of JSON format.

⚠️ This is not a logging library!

Main purpose is to help you test readers in your own programs.

Usage

Write text logs to stdout:

if err := dummylog.New().Start(ctx); err != nil {
    return err
}

Write JSON structured logs to stdout:

if err := dummylog.New(dummylog.WithFormat(dummylog.JSON)).Start(ctx); err != nil {
    return err
}

Write JSON structured logs to file:

file, createErr := os.Create(filePath)
if createErr != nil {
    return createErr
}

dummy := dummylog.New(dummylog.WithWriter(file), dummylog.WithFormat(dummylog.JSON))
if err := dummy.Start(ctx); err != nil {
    return err
}

⌨️ Command line interface

Run dummylog as a process to prints messages to file or to stdout:

./dummylog run

flags: 
  -format - sets log format: 'text' or 'json'. Default is text.
  -file   - sets path to file where logs will be written, 
            if flag is not present, logs will written to stdout.

Run dummylog as a server which listen to POST :8080/say and prints request body as message to file or to stdout:

./dummylog serve

flags: 
    -file - sets path to file where logs will be written, if 
            flag is not present, logs will written to stdout.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DummyLogger

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

DummyLogger represents a process which will write silly messages to underlying writer. Implements io.Writer interface by writing silly message into given byte slice.

func New

func New(options ...Option) *DummyLogger

func (*DummyLogger) Serve

func (l *DummyLogger) Serve(ctx context.Context) error

func (*DummyLogger) Start

func (l *DummyLogger) Start(ctx context.Context) error

func (*DummyLogger) Write

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

type Format

type Format string
const (
	// JSON represents text format for dummy logs.
	JSON Format = "json"
	// Text represents text format for dummy logs.
	Text Format = "text"
)

func (Format) String

func (f Format) String() string

type Option

type Option func(l *DummyLogger)

Option represents functional options pattern for DummyLogger type, a function which receive a pointer to DummyLogger struct. Option functions can only be passed to DummyLogger constructor function New, and can change the default value of DummyLogger struct.

func WithFormat

func WithFormat(format Format) Option

WithFormat sets DummyLogger log format.

func WithServerAddr

func WithServerAddr(addr string) Option

WithServerAddr sets DummyLogger server address.

func WithWriter

func WithWriter(writer io.Writer) Option

WithWriter sets DummyLogger writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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