logger
This commit is contained in:
@@ -3,9 +3,27 @@ package mdb
|
||||
import (
|
||||
"context"
|
||||
"kurumibot/laniakea"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ConsoleLogEntry struct {
|
||||
Level string `bson:"level"`
|
||||
Prefix string `bson:"prefix"`
|
||||
Traceback string `bson:"traceback"`
|
||||
Message string `bson:"message"`
|
||||
Time time.Time `bson:"time"`
|
||||
TimeStamp int64 `bson:"time_stamp"`
|
||||
}
|
||||
|
||||
func WriteConsoleLog(db *laniakea.DatabaseContext, e *ConsoleLogEntry) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("logs")
|
||||
_, err := col.InsertOne(ctx, e)
|
||||
return err
|
||||
}
|
||||
|
||||
type MessageLogEntry struct {
|
||||
MessageID int `bson:"messageId"`
|
||||
SenderID int `bson:"senderId"`
|
||||
@@ -17,7 +35,7 @@ type MessageLogEntry struct {
|
||||
func WriteMessageLog(db *laniakea.DatabaseContext, e *MessageLogEntry) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
collection := db.MongoDB.Database("kurumi").Collection("msg_logs")
|
||||
collection := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("msg_logs")
|
||||
_, err := collection.InsertOne(ctx, e)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user