Initial logging implementation
This commit is contained in:
parent
9a18ddd0f7
commit
a4ac7f50d3
|
@ -21,3 +21,4 @@ test/conf.json
|
|||
srv
|
||||
server
|
||||
server.bak
|
||||
testlogrus.log
|
||||
|
|
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module git.ververis.eu/mandi/godovecot
|
|||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/zloylos/grsync v1.5.1
|
||||
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce
|
||||
)
|
||||
|
|
7
go.sum
7
go.sum
|
@ -1,14 +1,19 @@
|
|||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/zloylos/grsync v1.5.1 h1:ZK+4ikSrXftZUndmC3rYZt7WHvyT2WoZz1MBTztxDo4=
|
||||
github.com/zloylos/grsync v1.5.1/go.mod h1:2utuy8p4VcWXfB5p9wTL+VCberFM+MwTDjDf1nr8s78=
|
||||
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce h1:Roh6XWxHFKrPgC/EQhVubSAGQ6Ozk6IdxHSzt1mR0EI=
|
||||
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
|
|
17
godovecot.go
17
godovecot.go
|
@ -23,6 +23,19 @@ import (
|
|||
|
||||
const serialServerPath string = "srv"
|
||||
|
||||
type ServerLogger interface {
|
||||
Println(v ...interface{})
|
||||
//Error(v ...interface{})
|
||||
}
|
||||
|
||||
func (s *server) Println(l ...interface{}) {
|
||||
s.server.Log.Println(l...)
|
||||
}
|
||||
|
||||
func (s *server) Error(l ...interface{}) {
|
||||
//s.server.Log.Error(l...)
|
||||
}
|
||||
|
||||
type MailServer struct {
|
||||
ApiConfig ApiConfig
|
||||
SSHConfig SSHConfig
|
||||
|
@ -31,6 +44,7 @@ type MailServer struct {
|
|||
BackupAccountsPath string
|
||||
MailDirOwner string
|
||||
MailDirGroup string
|
||||
Log ServerLogger
|
||||
}
|
||||
|
||||
type server struct {
|
||||
|
@ -126,6 +140,9 @@ func (s *server) TestSSH() error {
|
|||
return err
|
||||
}
|
||||
|
||||
//s.server.Log.Error("An error occured")
|
||||
s.Println("Shit an error occured")
|
||||
|
||||
fmt.Println("Test SSH gave back: ", string(out))
|
||||
return nil
|
||||
}
|
||||
|
|
16
test/main.go
16
test/main.go
|
@ -11,6 +11,7 @@ import (
|
|||
"time"
|
||||
|
||||
dovecot "git.ververis.eu/mandi/godovecot"
|
||||
logrus "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -18,6 +19,16 @@ func main() {
|
|||
/*
|
||||
*/
|
||||
|
||||
f, err := os.OpenFile("testlogrus.log", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
fmt.Printf("error opening file: %v", err)
|
||||
}
|
||||
|
||||
logger := logrus.New()
|
||||
logger.SetOutput(f)
|
||||
|
||||
//logg := log.Default()
|
||||
|
||||
ds := dovecot.MailServer{
|
||||
ApiConfig: dovecot.ApiConfig{
|
||||
ApiHost: "https://plesk.ververis.eu",
|
||||
|
@ -36,6 +47,9 @@ func main() {
|
|||
BackupAccountsPath: "sync/accounts",
|
||||
MailDirOwner: "popuser",
|
||||
MailDirGroup: "popuser",
|
||||
|
||||
Log: logger,
|
||||
//Log: logg,
|
||||
}
|
||||
|
||||
dv := ds.NewServer()
|
||||
|
@ -100,7 +114,7 @@ func main() {
|
|||
|
||||
/*
|
||||
*/
|
||||
err := dv.TestSSH()
|
||||
err = dv.TestSSH()
|
||||
if err != nil {
|
||||
fmt.Println("Test SSH: ", err)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# github.com/sirupsen/logrus v1.8.1
|
||||
## explicit; go 1.13
|
||||
github.com/sirupsen/logrus
|
||||
# github.com/zloylos/grsync v1.5.1
|
||||
## explicit; go 1.13
|
||||
github.com/zloylos/grsync
|
||||
|
@ -17,3 +20,6 @@ golang.org/x/crypto/ssh/knownhosts
|
|||
# golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1
|
||||
## explicit; go 1.17
|
||||
golang.org/x/sys/cpu
|
||||
golang.org/x/sys/internal/unsafeheader
|
||||
golang.org/x/sys/unix
|
||||
golang.org/x/sys/windows
|
||||
|
|
Loading…
Reference in New Issue