Improve logging

This commit is contained in:
Manfred Touron 2017-12-04 11:13:36 +01:00
parent edb230b278
commit 10f4ad49d9
3 changed files with 10 additions and 3 deletions

6
db.go
View file

@ -327,6 +327,10 @@ func NewEvent(domain, action string) *Event {
}
}
func (e *Event) String() string {
return fmt.Sprintf("%s %s %s %s", e.Domain, e.Action, e.Entity, string(e.Args))
}
func (e *Event) Log(db *gorm.DB) {
if len(e.ArgsMap) > 0 {
var err error
@ -334,7 +338,7 @@ func (e *Event) Log(db *gorm.DB) {
log.Printf("error: %v", err)
}
}
log.Printf("event: %v", e)
log.Printf("info: %s", e)
if err := db.Create(e).Error; err != nil {
log.Printf("warning: %v", err)
}

View file

@ -2,6 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"time"
@ -12,7 +13,9 @@ import (
)
func dbInit(db *gorm.DB) error {
log.SetOutput(ioutil.Discard)
db.Callback().Delete().Replace("gorm:delete", hardDeleteCallback)
log.SetOutput(os.Stderr)
m := gormigrate.New(db, gormigrate.DefaultOptions, []*gormigrate.Migration{
{
@ -530,7 +533,7 @@ func dbInit(db *gorm.DB) error {
if err := db.Create(&user).Error; err != nil {
return err
}
log.Printf("Admin user created, use the user 'invite:%s' to associate a public key with this account", user.InviteToken)
log.Printf("info 'admin' user created, use the user 'invite:%s' to associate a public key with this account", user.InviteToken)
}
// create host ssh key

View file

@ -269,6 +269,6 @@ func server(c *cli.Context) error {
return nil
})
log.Printf("SSH Server accepting connections on %s", c.String("bind-address"))
log.Printf("info: SSH Server accepting connections on %s", c.String("bind-address"))
return ssh.ListenAndServe(c.String("bind-address"), nil, opts...)
}