qalam

package module
v0.0.0-...-527fae9 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: MIT Imports: 7 Imported by: 0

README

qalam

Simple time based filewriter to log data to disk. Has buffer support to flush data from memory to disk to reduce disk IO

Features

  • Create a simple log file handler, will do log rotation automatically

Installing

go get -u github.com/arriqaaq/qalam

Example

Here's a full example of a qalam that writes to a file with a (%Y%m%d) format:

You can run this example from a terminal:

go run example/main.go
package main

import (
	"github.com/arriqaaq/qalam"
	"log"
	"time"
)

func main() {
	config := qalam.NewConfig("./log.%Y%m%d.gz", time.Local, 1, true, 10*time.Millisecond)
	c, err := qalam.NewQalam(config)
	if err != nil {
		log.Fatalln(err)
	}
	c.Writeln([]byte("pogba"))
	c.Writeln([]byte("kante"))
	c.Close()
}

TODO

  • Add more test cases
  • Add prometheus stats
  • Add zap logger for debug purpose

References

Contact

Farhan @arriqaaq

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBufferSize = 4096
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Location            string
	TimeLocation        *time.Location
	BufferSize          int
	EnablePeriodicFlush bool
	FlushInterval       time.Duration
}

func NewConfig

func NewConfig(loc string, timeLoc *time.Location, bufSize int, enableTimer bool, interval time.Duration) *Config

func (*Config) Validate

func (c *Config) Validate() error

type Qalam

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

func New

func New(location string) *Qalam

func NewQalam

func NewQalam(config *Config) (*Qalam, error)

func (*Qalam) Close

func (q *Qalam) Close()

A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes. It is not common for a file system to flush the buffers when the stream is closed. If you need to be sure that the data is physically stored use fsync(2). (It will depend on the disk hardware at this point.)

func (*Qalam) Likho

func (q *Qalam) Likho(b []byte) (int, error)

func (*Qalam) Likholn

func (q *Qalam) Likholn(b []byte) (int, error)

func (*Qalam) SetBufferSize

func (q *Qalam) SetBufferSize(b int)

SetBufferSize set's the size of the buffer which is kept in memory before pushing to disk. Defaults to 4096, the default page size on older SSDs, can be set accordingly

func (*Qalam) Write

func (q *Qalam) Write(b []byte) (int, error)

func (*Qalam) Writeln

func (q *Qalam) Writeln(b []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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