Skip to content
Snippets Groups Projects
Commit 59314382 authored by Pea Nut's avatar Pea Nut
Browse files

Close log file during teardown

cli (cmd/bitmask-helper/main.go and) and helpers (pkg/pickle/helpers.go)
were also fixed.
parent 8fac888a
No related branches found
No related tags found
1 merge request!225Close log file during teardown + some code cleanup
......@@ -35,6 +35,7 @@ var (
func main() {
config.LogPath = path.Join(config.Path, logFile)
config.ConfigureLogger()
defer config.CloseLogger()
helper.Version = Version
helper.AppName = AppName
......
......@@ -69,12 +69,14 @@ func initializeBitmask(errCh chan string, opts *InitOpts) {
b, err := bitmask.InitializeBitmask(ctx.cfg)
if err != nil {
config.CloseLogger()
log.Error().
Err(err).
Msg("Could not initialize bitmask")
errCh <- err.Error()
return
}
// right now we just get autostart from an init flag,
// but we want to be able to persist that option from the preferences
// pane
......
......@@ -22,10 +22,12 @@ import (
"github.com/rs/zerolog/log"
)
var logFile *os.File
func ConfigureLogger() {
os.MkdirAll(Path, 0750)
runLogFile, _ := os.OpenFile(
logFile, _ = os.OpenFile(
LogPath,
os.O_RDWR|os.O_CREATE|os.O_APPEND,
0644,
......@@ -35,7 +37,7 @@ func ConfigureLogger() {
TimeFormat: "2006-01-02T15:04:05.999Z07:00",
}
multi := zerolog.MultiLevelWriter(consoleWriter, runLogFile)
multi := zerolog.MultiLevelWriter(consoleWriter, logFile)
log.Logger = zerolog.New(multi).With().Timestamp().Logger()
envLogLevel := os.Getenv("LOG_LEVEL")
......@@ -52,3 +54,7 @@ func ConfigureLogger() {
Str("hint", "you can change the log level with env LOG_LEVEL=INFO|DEBUG|TRACE").
Msg("Enabling logging")
}
func CloseLogger() {
logFile.Close()
}
......@@ -132,6 +132,7 @@ func dumpHelper(fname, dest string, isExec bool) {
func InstallHelpers() {
// logger is not configured at this point
config.ConfigureLogger()
defer config.CloseLogger()
// this function can be called by command line argument: riseup-vpn --install-helpers
log.Info().Msg("Installing helpers")
......
......@@ -158,6 +158,8 @@ func (b *Bitmask) GetSnowflakeCh() <-chan *snowflake.StatusEvent {
// Close the connection to bitmask, and does cleanup of temporal files
func (b *Bitmask) Close() {
log.Info().Msg("Close: cleanup and vpn shutdown...")
defer config.CloseLogger()
err := b.StopVPN()
if err != nil {
log.Warn().
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment