writers

package module
v0.0.0-...-07623ef Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 11 Imported by: 2

README

writerss

Build Status | codecov | Go Report Card | GoDoc

A starting project with writer interface implementations.

If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

With support for

  • file (with queue processing)[1]
  • stdout (with queue processing)[1] [here]

[1] this writer allows you to continue the processing and dispatch the logging

Dependecy Management

Dep

Project dependencies are managed using Dep. Read more about Dep.

  • Install dependencies: dep ensure
  • Update dependencies: dep ensure -update
Go
go get github.com/joaosoft/writers

Interface

type writer interface {
	Write(p []byte) (n int, err error)
}

Usage

This examples are available in the project at writers/examples

quit := make(chan bool)
//
// file writers
writer := writers.NewFileWriter(
    writers.WithDirectory("./testing"),
    writers.WithFileName("dummy_"),
    writers.WithFileMaxMegaByteSize(1),
    writers.WithFlushTime(time.Second),
    writers.WithQuitChannel(quit),
)

// logger
log := logger.NewLog(
    logger.WithLevel(logger.InfoLevel),
    logger.WithFormatHandler(logger.JsonFormatHandler),
    logger.WithWriter(writer)).WithPrefixes(map[string]interface{}{
    "level":   logger.LEVEL,
    "time":    logger.TIME,
    "service": "writers"})

fmt.Printf("send...")
for i := 1; i < 100000; i++ {
    log.Info(fmt.Sprintf("hello number %d\n", i))
}
fmt.Printf("sent!")

// wait one minute to process...
<-time.After(time.Minute * 1)
quit <- true

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Overview

GoWriter helps to create specific writers, eventually to use in a logging service like https://github.com/joaosoft/go-log

examples at https://github.com/joaosoft/writer/tree/master/example

Index

Constants

View Source
const (
	MB_IN_BYTE = 1000000
)

Variables

This section is empty.

Functions

func JsonFormatHandler

func JsonFormatHandler(prefixes map[string]interface{}, tags map[string]interface{}, message interface{}, fields map[string]interface{}, sufixes map[string]interface{}) ([]byte, error)

func TextFormatHandler

func TextFormatHandler(prefixes map[string]interface{}, tags map[string]interface{}, message interface{}, fields map[string]interface{}, sufixes map[string]interface{}) ([]byte, error)

Types

type FileConfig

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

FileConfig ...

type FileWriter

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

FileWriter ...

func NewFileWriter

func NewFileWriter(options ...FileWriterOption) *FileWriter

NewFileWriter ...

func (*FileWriter) Reconfigure

func (fileWriter *FileWriter) Reconfigure(options ...FileWriterOption)

Reconfigure ...

func (*FileWriter) SWrite

func (fileWriter *FileWriter) SWrite(prefixes map[string]interface{}, tags map[string]interface{}, message interface{}, fields map[string]interface{}, sufixes map[string]interface{}) (n int, err error)

SWrite ...

func (*FileWriter) Write

func (fileWriter *FileWriter) Write(message []byte) (n int, err error)

Write ...

type FileWriterOption

type FileWriterOption func(fileWriter *FileWriter)

StdoutWriterOption ...

func WithFileDirectory

func WithFileDirectory(directory string) FileWriterOption

WithFileDirectory ...

func WithFileFlushTime

func WithFileFlushTime(flushTime time.Duration) FileWriterOption

WithFileFlushTime ...

func WithFileFormatHandler

func WithFileFormatHandler(formatHandler FormatHandler) FileWriterOption

WithFileFormatHandler ...

func WithFileMaxMegaByteSize

func WithFileMaxMegaByteSize(fileMaxSize int64) FileWriterOption

WithFileMaxMegaByteSize ...

func WithFileName

func WithFileName(fileName string) FileWriterOption

WithFileName ...

func WithFileQuitChannel

func WithFileQuitChannel(quit chan bool) FileWriterOption

WithFileQuitChannel ...

type FormatHandler

type FormatHandler func(prefixes map[string]interface{}, tags map[string]interface{}, message interface{}, fields map[string]interface{}, sufixes map[string]interface{}) ([]byte, error)

type IList

type IList interface {
	Add(id string, data interface{}) error
	Remove(ids ...string) interface{}
	Size() int
	IsEmpty() bool
	Dump() string
}

IList ...

func NewQueue

func NewQueue(options ...QueueOption) IList

NewQueue ...

type Message

type Message struct {
	Prefixes map[string]interface{} `json:"prefixes,omitempty"`
	Tags     map[string]interface{} `json:"tags,omitempty"`
	Message  interface{}            `json:"message,omitempty"`
	Fields   map[string]interface{} `json:"fields,omitempty"`
	Sufixes  map[string]interface{} `json:"sufixes,omitempty"`
}

type Mode

type Mode int

Mode ...

const (
	// First In First Out
	FIFO Mode = iota
	// Last In Last Out
	LIFO
)

type Queue

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

Queue ...

func (*Queue) Add

func (queue *Queue) Add(id string, data interface{}) error

Add ...

func (*Queue) Dump

func (queue *Queue) Dump() string

Dump ...

func (*Queue) IsEmpty

func (queue *Queue) IsEmpty() bool

IsEmpty ...

func (*Queue) Reconfigure

func (queue *Queue) Reconfigure(options ...QueueOption)

Reconfigure ...

func (*Queue) Remove

func (queue *Queue) Remove(ids ...string) interface{}

Remove ...

func (*Queue) Size

func (queue *Queue) Size() int

Size ...

type QueueOption

type QueueOption func(queue *Queue)

QueueOption ...

func WithMaxSize

func WithMaxSize(size int) QueueOption

WithMaxSize ...

func WithMode

func WithMode(mode Mode) QueueOption

WithMode ...

type StdoutWriter

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

StdoutWriter ...

func NewStdoutWriter

func NewStdoutWriter(options ...StdoutWriterOption) *StdoutWriter

NewStdoutWriter ...

func (*StdoutWriter) Reconfigure

func (stdoutWriter *StdoutWriter) Reconfigure(options ...StdoutWriterOption)

Reconfigure ...

func (*StdoutWriter) SWrite

func (stdoutWriter *StdoutWriter) SWrite(prefixes map[string]interface{}, tags map[string]interface{}, message interface{}, fields map[string]interface{}, sufixes map[string]interface{}) (n int, err error)

SWrite ...

func (*StdoutWriter) Write

func (stdoutWriter *StdoutWriter) Write(message []byte) (n int, err error)

Write ...

type StdoutWriterOption

type StdoutWriterOption func(fileWriter *StdoutWriter)

StdoutWriterOption ...

func WithStdoutFlushTime

func WithStdoutFlushTime(flushTime time.Duration) StdoutWriterOption

WithStdoutFlushTime ...

func WithStdoutFormatHandler

func WithStdoutFormatHandler(formatHandler FormatHandler) StdoutWriterOption

WithStdoutFormatHandler ...

func WithStdoutQuitChannel

func WithStdoutQuitChannel(quit chan bool) StdoutWriterOption

WithStdoutQuitChannel ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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