mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-25 02:20:43 +01:00
logging: extract command fields, add default fields for logged commands
This commit is contained in:
parent
de423cc927
commit
4ee79b5fe4
@ -77,16 +77,23 @@ func LogCommand(command interface{}) {
|
|||||||
|
|
||||||
commandName := reflect.TypeOf(command).Elem().Name()
|
commandName := reflect.TypeOf(command).Elem().Name()
|
||||||
|
|
||||||
customLogger.WithFields(logrus.Fields{
|
var commandAsFields logrus.Fields
|
||||||
|
json.Unmarshal(context, &commandAsFields)
|
||||||
|
|
||||||
|
customLogger.
|
||||||
|
WithFields(defaultFields).
|
||||||
|
WithFields(logrus.Fields{
|
||||||
"command_name": commandName,
|
"command_name": commandName,
|
||||||
"command": string(context),
|
"command": commandAsFields,
|
||||||
}).Info("Start command " + commandName)
|
}).Info("Start command " + commandName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogCommandFailed(command interface{}, err error) {
|
func LogCommandFailed(command interface{}, err error) {
|
||||||
commandName := reflect.TypeOf(command).Elem().Name()
|
commandName := reflect.TypeOf(command).Elem().Name()
|
||||||
|
|
||||||
customLogger.WithFields(logrus.Fields{
|
customLogger.
|
||||||
|
WithFields(defaultFields).
|
||||||
|
WithFields(logrus.Fields{
|
||||||
"reason": err.Error(),
|
"reason": err.Error(),
|
||||||
}).Info("Command failed" + commandName)
|
}).Info("Command failed" + commandName)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user