log

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: Apache-2.0 Imports: 21 Imported by: 6

Documentation

Overview

Package log defined a logger

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	ID string
	// contains filtered or unexported fields
}

Logger represents file system transaction logger

func New

func New(config *config.Stream, ID string, fs afs.Service) (*Logger, error)

New creates a transaction logger

func (*Logger) Close

func (l *Logger) Close() (err error)

Close closes logger

func (*Logger) Log

func (l *Logger) Log(message msg.Message) (err error)

Log logs a message

Example
package main

import (
	"github.com/viant/afs"
	"github.com/viant/tapper/config"
	"github.com/viant/tapper/log"
	"github.com/viant/tapper/msg"
	"github.com/viant/tapper/msg/json"

	slog "log"
)

func main() {

	cfg := &config.Stream{
		URL:   "/tmp/logfile.log",
		Codec: "gzip",
		Rotation: &config.Rotation{
			EveryMs: 100,
			URL:     "/tmp/logfile.log.[yyyyMMdd_HH]-%v",
		},
	}
	logger, err := log.New(cfg, "myID", afs.New())
	if err != nil {
		slog.Fatal(err)
	}
	provider := msg.NewProvider(2048, 32, json.New)

	for i := 0; i < 100; i++ {
		message := provider.NewMessage()
		message.PutString("k1", "value1")
		message.PutInt("k2", 2)
		message.PutStrings("k3", []string{"1", "3"})
		err = logger.Log(message)
		if err != nil {
			slog.Fatal(err)
		}
		message.Free()
	}
	logger.Close()
}
Output:

Jump to

Keyboard shortcuts

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