logstream

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 6 Imported by: 0

README

logstream

logstream is simple library for logging

install

go get github.com/snowmerak/logstream

use

package main

import (
	"context"
	"time"

	"github.com/snowmerak/logstream"
	"github.com/snowmerak/logstream/log"
	"github.com/snowmerak/logstream/log/logbuffer/logqueue/logquebuf"
	"github.com/snowmerak/logstream/log/logbuffer/logring/logringbuf"
	"github.com/snowmerak/logstream/log/loglevel"
	"github.com/snowmerak/logstream/log/writable/stdout"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// using proirity queue for log buffer
	ls := logstream.New(ctx, logquebuf.New(8), 8)
	ls.ObserveTopic("A", stdout.New(ctx, loglevel.All, nil))

	for i := 0; i < 10; i++ {
		ls.Write("A", log.New(loglevel.Fatal, "qp time test log").End())
	}

	fmt.Println("----------")

	// using ringbuffer for log buffer
	ls = logstream.New(ctx, logringbuf.New(8), 8)
	ls.ObserveTopic("A", stdout.New(ctx, loglevel.All, nil))

	for i := 0; i < 10; i++ {
		ls.Write("A", log.New(loglevel.Fatal, "rb time test log").End())
	}

	time.Sleep(1 * time.Second)
}
2022-01-03T14:02:14.048117+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.048119+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.04812+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.048121+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.048121+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.048122+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.048123+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.048123+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.048124+09:00 [FATAL] qp time test log
2022-01-03T14:02:14.048168+09:00 [FATAL] qp time test log
----------
2022-01-03T14:02:14.048331+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048335+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048335+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048336+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048336+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048337+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048337+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048337+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048338+09:00 [FATAL] rb time test log
2022-01-03T14:02:14.048354+09:00 [FATAL] rb time test log

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogBuffer

type LogBuffer interface {
	AddTopic(topic string, signal chan struct{})
	RemoveTopic(topic string)
	EnQueue(topic string, value log.Log)
	DeQueue(topic string) (log.Log, error)
}

type LogStream

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

func New

func New(ctx context.Context, buf LogBuffer, bufSize int) *LogStream

func (*LogStream) ObserveTopic

func (ls *LogStream) ObserveTopic(topic string, writers ...writable.Writable) error

func (*LogStream) Write

func (ls *LogStream) Write(topic string, l log.Log)

Jump to

Keyboard shortcuts

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