writer

package module
v0.0.0-...-46084e3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 14 Imported by: 0

README

writer

A write efficient log writer.

Documentation

Index

Constants

View Source
const (
	NewLine byte = '\n'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Compactor

type Compactor interface {
	Listen(ch <-chan SegmentFile)
}

func NewCompactor

func NewCompactor(indexer Indexer) Compactor

type Indexer

type Indexer interface {
	WriteIndex(index int64) error
	IndexLen() int
}

func NewIndexer

func NewIndexer(logDirectoryPath string) (Indexer, error)

type Log

type Log struct {
	Timestamp       time.Time
	Level           LogLevel
	TimestampFormat LogTimeFormat
	Message         []byte
}

Message is an abstraction of log message

func NewLog

func NewLog(msg []byte, logLevel LogLevel, timestampFormat LogTimeFormat) *Log

NewLog wraps the message with log formatted message

func (*Log) Format

func (l *Log) Format() []byte

Format returns in log format - "timestamp loglevel message"

func (*Log) Size

func (l *Log) Size() int

Size returns the size of the log

func (*Log) String

func (l *Log) String() string

func (*Log) Unmarshal

func (l *Log) Unmarshal(b []byte) error

Unmarshal unmarshalls the byte slice into Log

type LogLevel

type LogLevel string
const (
	LogLevelTrace LogLevel = "trace"
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
	LogLevelFatal LogLevel = "fatal"
)

type LogTimeFormat

type LogTimeFormat string
const (
	LogTimeFormatLocalTime LogTimeFormat = "[Jan 2 2006 15:04:05]"
	LogTimeFormatUTC       LogTimeFormat = "[2006-01-02T15:04:05Z]"
)

type Memtable

type Memtable struct {
	Logs           bytes.Buffer
	StartTimeStamp int64
	OccupiedSize   int
	TotalSize      int
}

func NewMemtable

func NewMemtable(totalSize int) Memtable

NewMemtable returns a new instance of Memtable

func (*Memtable) Append

func (m *Memtable) Append(log []byte, timestamp time.Time) error

Append appends the log in the running memtable

func (*Memtable) Flush

func (m *Memtable) Flush(w io.Writer) error

Flush flushes the logs from memtable to segmentfile

type SegmentFile

type SegmentFile struct {
	Name           string
	StartTimeStamp int64
	LogDirectory   string
	OccupiedSize   int
	Size           int
	Path           string
	Out            io.ReadWriteCloser
}

func NewSegmentFile

func NewSegmentFile(logDirectory string, startTimeStamp int64, size int) (*SegmentFile, error)

func (*SegmentFile) Close

func (s *SegmentFile) Close() error

func (*SegmentFile) Reader

func (s *SegmentFile) Reader() io.Reader

func (*SegmentFile) Writer

func (s *SegmentFile) Writer() io.Writer

type Writer

type Writer interface {
	// Write reads from r and writes it to out
	Write(r io.Reader) (n int, err error)

	//SetLogLevel sets the given logLevel
	SetLogLevel(logLevel LogLevel)

	//SetLogTimeFormat overrides the logTimeFormat
	// default logTimeFormat is Local Time
	SetLogTimeFormat(logTimeFormat LogTimeFormat)

	Replay() error

	// Close closes flushes the running memtable
	// anc closes the writer
	Close() error
}

Writer provides an interface to write logs to desired target store

func New

func New(logDirectory string, memtableSize int, segmentFileSize int) Writer

New returns a new instance of writer

Directories

Path Synopsis
cmd
app

Jump to

Keyboard shortcuts

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