summaryrefslogtreecommitdiff
path: root/src/log.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
commitb1d92b395322f2164ccfb44b0f7caebbaece6b62 (patch)
tree2133e4045b4af4d07a98674b7ae3a234670f0305 /src/log.go
parent3a4ae2942b43923ff98fd2eca8878c3cf145686c (diff)
Refactor: Restructure project
- Add an internal folder where all the internal code lives - Make a state.go and state_test.go for the public interface This gives a more clear separation between functions and modules. It also makes this a more typical Go project setup.
Diffstat (limited to 'src/log.go')
-rw-r--r--src/log.go66
1 files changed, 0 insertions, 66 deletions
diff --git a/src/log.go b/src/log.go
deleted file mode 100644
index 7402e31..0000000
--- a/src/log.go
+++ /dev/null
@@ -1,66 +0,0 @@
-package eduvpn
-
-import (
- "fmt"
- "log"
- "os"
- "path"
-)
-
-type FileLogger struct {
- Level LogLevel
- File *os.File
-}
-
-type LogLevel int8
-
-const (
- LOG_NOTSET LogLevel = iota
- LOG_INFO
- LOG_WARNING
- LOG_ERROR
-)
-
-func (e LogLevel) String() string {
- switch e {
- case LOG_NOTSET:
- return "NOTSET"
- case LOG_INFO:
- return "INFO"
- case LOG_WARNING:
- return "WARNING"
- case LOG_ERROR:
- return "ERROR"
- default:
- return "UNKNOWN"
- }
-}
-
-func (eduvpn *VPNState) getLogFilename() string {
- pathString := path.Join(eduvpn.ConfigDirectory, eduvpn.Name)
- return fmt.Sprintf("%s.log", pathString)
-}
-
-func (eduvpn *VPNState) InitLog(level LogLevel) error {
- configDirErr := eduvpn.EnsureConfigDir()
- if configDirErr != nil {
- return configDirErr
- }
- logFile, logOpenErr := os.OpenFile(eduvpn.getLogFilename(), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666)
- if logOpenErr != nil {
- return logOpenErr
- }
- log.SetOutput(logFile)
- eduvpn.LogFile = FileLogger{Level: level, File: logFile}
- return nil
-}
-
-func (eduvpn *VPNState) Log(level LogLevel, str string) {
- if level >= eduvpn.LogFile.Level && eduvpn.LogFile.Level != LOG_NOTSET {
- log.Printf("[%s]: %s", level.String(), str)
- }
-}
-
-func (eduvpn *VPNState) CloseLog() {
- eduvpn.LogFile.File.Close()
-}