Added description in README.md

This commit is contained in:
mandi 2022-04-25 20:43:29 +02:00
parent 468a4062af
commit ccc3a3989a
1 changed files with 68 additions and 0 deletions

View File

@ -43,6 +43,74 @@ MailDirGroup | string | User of Maildir (used on `chown`) | Account restore
Returns: server struct instance `srv`
## Logging
Problem statement
To implement logging using a module (like logrus) the functions must be implemented either in main.go or in dovecot using exactly the choosen module.
Using an other module later would be a huge effort for refactoring
Solution
To be able to use any logging api you want logging is implemented as callbacks including seperate functions for
- Info
- Error
- Warn
- Fatal
A struct containing the callbacks for above log-levels is created as `godovecot.Logger`. This is allocated at server-creation in the followimg way
````golang
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)
log := log.Default()
sl := dovecot.Logger{
LogError: func(e ...interface{}) {
//log.Println(e)
logger.Error(e)
},
LogInfo: func(i ...interface{}) {
//log.Println(i)
logger.Info(i)
},
LogWarn: func(w ...interface{}) {
//log.Println(w)
logger.Warn(w)
},
}
ds := dovecot.MailServer{
ApiConfig: &dovecot.ApiConfig{
ApiHost: "https://plesk.ververis.eu",
ApiUser: "admin",
Password: "Sektor@mailD2312",
},
SSHConfig: &dovecot.SSHConfig{
SSHHost: "89.22.111.212",
SSHPort: "22",
SSHUser: "root",
LocalPrivateKeyPath: "/Users/mandi/.ssh/id_rsa",
LocalKnownHostPath: "/Users/mandi/.ssh/known_hosts",
},
MaildirPath: "/var/qmail/mailnames/ververis.eu",
BakupMailsPath: "sync",
BackupAccountsPath: "sync/accounts",
MailDirOwner: "popuser",
MailDirGroup: "popuser",
Logger: &sl,
}
````
Above example shows implementation using `sirupsen/logrus`
https://github.com/sirupsen/logrus
### RestoreMail(a ...IPacket)
`ResroreMail(a ...IPacket)` is implemented as variadic to be able to pass parameters as different types implementing the `IPacket` interface: