| 1 |
// +build windows |
| 2 |
|
| 3 |
package persistentlog |
| 4 |
|
| 5 |
import ( |
| 6 |
"os" |
| 7 |
"path/filepath" |
| 8 |
|
| 9 |
"github.com/rifflock/lfshook" |
| 10 |
log "github.com/sirupsen/logrus" |
| 11 |
) |
| 12 |
|
| 13 |
// AddPersistentLogHook configures persisting logs in a file |
| 14 |
func AddPersistentLogHook() { |
| 15 |
appDataPath := os.Getenv("LOCALAPPDATA") |
| 16 |
if appDataPath == "" { |
| 17 |
log.Warn("Unable to determine %%APPDATA%% folder location, logs will NOT be persisted") |
| 18 |
return |
| 19 |
} |
| 20 |
logFolderPath := filepath.Join(appDataPath, "browserpass") |
| 21 |
if err := os.MkdirAll(logFolderPath, os.ModePerm); err != nil { |
| 22 |
log.Warn("Unable to create browserpass folder in %%APPDATA%%, logs will NOT be persisted: ", err) |
| 23 |
return |
| 24 |
} |
| 25 |
logFilePath := filepath.Join(logFolderPath, "browserpass.log") |
| 26 |
log.Debug("Logs will being written to: ", logFilePath) |
| 27 |
log.AddHook(lfshook.NewHook(logFilePath, &log.TextFormatter{FullTimestamp: true})) |
| 28 |
} |