github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/log/event.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package log
     4  
     5  import (
     6  	"runtime/debug"
     7  
     8  	"github.com/GeniusesGroup/libgo/event"
     9  	"github.com/GeniusesGroup/libgo/protocol"
    10  	// "github.com/GeniusesGroup/libgo/syllab"
    11  	"github.com/GeniusesGroup/libgo/time/unix"
    12  )
    13  
    14  // Event implement protocol.LogEvent
    15  type Event struct {
    16  	event.Event
    17  
    18  	message string
    19  	stack   []byte
    20  }
    21  
    22  func (e *Event) MainType() protocol.EventMainType { return protocol.EventMainType_Log }
    23  
    24  func (e *Event) Level() protocol.LogType { return e.Event.SubType() }
    25  func (e *Event) Message() string         { return e.message }
    26  func (e *Event) Stack() []byte           { return e.stack }
    27  
    28  func (e *Event) Init(level protocol.LogType, domain, message string, stack bool) {
    29  	e.message = message
    30  	if stack {
    31  		e.stack = debug.Stack()
    32  	}
    33  	// e.Event.SetSubType(level)
    34  	// e.Event.SetDomain(domain)
    35  	// e.Event.SetNodeID([16]byte{})
    36  	// e.Event.SetTime(unix.Now())
    37  	e.Event.Init(level, domain, [16]byte{}, unix.Now())
    38  }
    39  
    40  /*
    41  	-- protocol.Syllab interface --
    42  */
    43  func (e *Event) CheckSyllab(payload []byte) (err protocol.Error) {
    44  	if len(payload) < int(e.LenOfSyllabStack()) {
    45  		// err = &syllab.ErrShortArrayDecode
    46  	}
    47  	return
    48  }
    49  func (e *Event) FromSyllab(payload []byte, stackIndex uint32) {
    50  }
    51  func (e *Event) ToSyllab(payload []byte, stackIndex, heapIndex uint32) (freeHeapIndex uint32) {
    52  	return
    53  }
    54  func (e *Event) LenAsSyllab() uint64      { return uint64(e.LenOfSyllabStack() + e.LenOfSyllabHeap()) }
    55  func (e *Event) LenOfSyllabStack() uint32 { return 16 + e.Event.LenOfSyllabStack() }
    56  func (e *Event) LenOfSyllabHeap() (ln uint32) {
    57  	return uint32(len(e.stack)+len(e.message)) + e.Event.LenOfSyllabHeap()
    58  }