livelogs

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2020 License: MIT Imports: 3 Imported by: 0

README

Maintainability Test Coverage Go Test

Live Logs to Go

Livelogs is a library to stream logs to multiple watchers.

The logs could also be save into database with gorm.

livelogs

Example

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/blueworrybear/livelogs"
	"github.com/blueworrybear/livelogs/core"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/sqlite"
)

func main() {
	db, _ := gorm.Open("sqlite3", "core.db")
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	m := livelogs.NewLogManager(db)
	log, _ := m.Create()

	go func() {
		tail, _ := log.Tail(ctx)
		for {
			select {
			case line := <-tail:
				fmt.Println(line.Text)
			}
		}
	}()

	for {
		log.Write(ctx, &core.LogLine{Text: "log"})
		time.Sleep(1 * time.Second)
	}
}

Above code will keep print out log.

Documentation

Godoc

License

© Benno, 2020

Released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogManager

func NewLogManager(db *gorm.DB) core.LogManager

NewLogManager manages open logs

Types

This section is empty.

Directories

Path Synopsis
Package core is a generated GoMock package.
Package core is a generated GoMock package.
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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