44 lines
885 B
Go
44 lines
885 B
Go
|
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,
|
||
|
}
|
||
|
}
|