Add persistent logging: syslog for unix, file for windows (#6)
This commit is contained in:
13
Gopkg.lock
generated
13
Gopkg.lock
generated
@@ -2,8 +2,17 @@
|
|||||||
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/sirupsen/logrus"
|
name = "github.com/rifflock/lfshook"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
|
revision = "bf539943797a1f34c1f502d07de419b5238ae6c6"
|
||||||
|
version = "v2.3"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
name = "github.com/sirupsen/logrus"
|
||||||
|
packages = [
|
||||||
|
".",
|
||||||
|
"hooks/syslog"
|
||||||
|
]
|
||||||
revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc"
|
revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc"
|
||||||
version = "v1.0.5"
|
version = "v1.0.5"
|
||||||
|
|
||||||
@@ -25,6 +34,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "559be3832a82b6c8884ca8103c92b2343135b96374cdf98f6cc294427bd26219"
|
inputs-digest = "f6199a143c790c5c1422bd35477ede08e5d2e3a0e5552d769e7c4de6ed8a14b1"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
@@ -23,3 +23,7 @@
|
|||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/sirupsen/logrus"
|
name = "github.com/sirupsen/logrus"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
name = "github.com/rifflock/lfshook"
|
||||||
|
version = "2.3.0"
|
||||||
|
12
Makefile
12
Makefile
@@ -4,22 +4,22 @@ all: deps browserpass test
|
|||||||
deps:
|
deps:
|
||||||
dep ensure
|
dep ensure
|
||||||
|
|
||||||
browserpass: *.go
|
browserpass: *.go **/*.go
|
||||||
go build -o $@
|
go build -o $@
|
||||||
|
|
||||||
browserpass-linux64: *.go
|
browserpass-linux64: *.go **/*.go
|
||||||
env GOOS=linux GOARCH=amd64 go build -o $@
|
env GOOS=linux GOARCH=amd64 go build -o $@
|
||||||
|
|
||||||
browserpass-windows64: *.go
|
browserpass-windows64: *.go **/*.go
|
||||||
env GOOS=windows GOARCH=amd64 go build -o $@.exe
|
env GOOS=windows GOARCH=amd64 go build -o $@.exe
|
||||||
|
|
||||||
browserpass-darwinx64: *.go
|
browserpass-darwinx64: *.go **/*.go
|
||||||
env GOOS=darwin GOARCH=amd64 go build -o $@
|
env GOOS=darwin GOARCH=amd64 go build -o $@
|
||||||
|
|
||||||
browserpass-openbsd64: *.go
|
browserpass-openbsd64: *.go **/*.go
|
||||||
env GOOS=openbsd GOARCH=amd64 go build -o $@
|
env GOOS=openbsd GOARCH=amd64 go build -o $@
|
||||||
|
|
||||||
browserpass-freebsd64: *.go
|
browserpass-freebsd64: *.go **/*.go
|
||||||
env GOOS=freebsd GOARCH=amd64 go build -o $@
|
env GOOS=freebsd GOARCH=amd64 go build -o $@
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
3
main.go
3
main.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/maximbaz/browserpass-native/openbsd"
|
"github.com/maximbaz/browserpass-native/openbsd"
|
||||||
|
"github.com/maximbaz/browserpass-native/persistentlog"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@ func main() {
|
|||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
persistentlog.AddPersistentLogHook()
|
||||||
|
|
||||||
log.Debugf("Starting browserpass host app v%v", VERSION)
|
log.Debugf("Starting browserpass host app v%v", VERSION)
|
||||||
process()
|
process()
|
||||||
}
|
}
|
||||||
|
21
persistentlog/syslog.go
Normal file
21
persistentlog/syslog.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// +build !windows,!nacl,!plan9
|
||||||
|
|
||||||
|
package persistentlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/syslog"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
logSyslog "github.com/sirupsen/logrus/hooks/syslog"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddPersistentLogHook configures persisting logs in syslog
|
||||||
|
func AddPersistentLogHook() {
|
||||||
|
hook, err := logSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "browserpass")
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
log.AddHook(hook)
|
||||||
|
} else {
|
||||||
|
log.Warn("Unable to connect to syslog, logs will NOT be persisted")
|
||||||
|
}
|
||||||
|
}
|
10
persistentlog/unsupported.go
Normal file
10
persistentlog/unsupported.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// +build nacl,plan9
|
||||||
|
|
||||||
|
package persistentlog
|
||||||
|
|
||||||
|
import log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// AddPersistentLogHook configures persisting logs, not supported on these systems
|
||||||
|
func AddPersistentLogHook() {
|
||||||
|
log.Warn("Persistent logging is not implemented on this OS")
|
||||||
|
}
|
28
persistentlog/windows.go
Normal file
28
persistentlog/windows.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package persistentlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/rifflock/lfshook"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddPersistentLogHook configures persisting logs in a file
|
||||||
|
func AddPersistentLogHook() {
|
||||||
|
appDataPath := os.Getenv("LOCALAPPDATA")
|
||||||
|
if appDataPath == "" {
|
||||||
|
log.Warn("Unable to determine %%APPDATA%% folder location, logs will NOT be persisted")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logFolderPath := filepath.Join(appDataPath, "browserpass")
|
||||||
|
if err := os.MkdirAll(logFolderPath, os.ModePerm); err != nil {
|
||||||
|
log.Warn("Unable to create browserpass folder in %%APPDATA%%, logs will NOT be persisted")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logFilePath := filepath.Join(logFolderPath, "browserpass.log")
|
||||||
|
log.Debug("Logs will being written to: ", logFilePath)
|
||||||
|
log.AddHook(lfshook.NewHook(logFilePath, &log.TextFormatter{FullTimestamp: true}))
|
||||||
|
}
|
Reference in New Issue
Block a user