mirror of
https://github.com/moul/sshportal.git
synced 2024-09-20 15:06:07 +08:00
Improve logging
This commit is contained in:
parent
edb230b278
commit
10f4ad49d9
6
db.go
6
db.go
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
2
main.go
2
main.go
|
@ -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...)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue