Help us shape the future of Go! Take the 2026 Go Developer Survey

ivent

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 2 Imported by: 0

README

ivent

Logs as events, events as logs

Motivation

Diferent libraries choose a logging library for debug and traceability. Ivent pretends to move logging from author to users

Installation

    go get github.com/licaonfee/ivent

Usage

For libraries using ivent Logger
package lib

import (
    "github.com/licaonfee/ivent/log"
    "github.com/licaonfee/ivent/stream"
    )

var logger *ivent.Logger

func init(){
    //By default all clients use stream.Noop
    logger = log.NewLogger()
}

func DoSomethingWithIvent(){
    //do the thing
    logger.Trace("I do the thing")
}
For users
package main

import (
    "log"
    "github.com/licaonfee/ivent/stream"
    "github.com/licaonfee/ivent/log"
    "thelibrary/lib"
    )

func main(){
    stream := stream.NewSync()
    lib.logger.WithStream(stream)

    go func(){
        for e:= <-stream.Get(){
            log.Printf("%s : %s",e.Class, e.Data)
        }
    }

    //Prints:"Trace : I do the thing"
    lib.DoSomethingWithIvent()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any int

Any default Class Interface implementation

func (Any) String

func (a Any) String() string

String return Any as a numeric string

func (Any) Value

func (a Any) Value() int64

Value just return int(Any)

type Class

type Class interface {
	Value() int64
	String() string
}

Class interface to define custom event classes

type Client

type Client interface {
	//WithStream implementation must be concurrent safe
	WithStream(Stream)
}

Client this interface can be used by client libraries to send events final user must pass an implementation of Stream to this all implementations must be use default Noop Stream

type Event

type Event struct {
	T    Class
	Time time.Time
	Tags map[string]string
	Data interface{}
}

Event ss

func NewEvent

func NewEvent(t Class, tags map[string]string, d interface{}) Event

NewEvent create an event of type t qith data d and Time = Now

type Stream

type Stream interface {
	//Send all implementations of this method must be concurent safe
	Send(Event)
}

Stream this interface should be used for final users to get events from Client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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