This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
microservices-collection/logging/srv.go

44 lines
885 B
Go
Raw Normal View History

package logging
import (
"time"
"github.com/bdlm/log"
"github.com/satori/go.uuid"
"github.com/streadway/amqp"
)
const EXCHANGE = "sum7.logging"
func ExchangeDeclare(ch *amqp.Channel) error {
return ch.ExchangeDeclare(
EXCHANGE,
"direct",
true,
false,
false,
false,
nil,
)
}
type LogMessage struct {
ServiceName string `json:"sname"`
ServiceID uuid.UUID `json:"sid"`
Time time.Time `json:"time"`
Level uint32 `json:"level"`
Message string `json:"message"`
Data map[string]interface{} `json:"data"`
}
func LogMessageFromEntry(sname string, sid uuid.UUID, e *log.Entry) *LogMessage {
return &LogMessage{
ServiceName: sname,
ServiceID: sid,
Time: e.Time,
Level: uint32(e.Level),
Message: e.Message,
Data: e.Data,
}
}