forked from konstructio/kubefirst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (66 loc) · 1.97 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
Copyright © 2022 Kubefirst Inc. [email protected]
*/
package main
import (
"fmt"
stdLog "log"
"os"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/kubefirst/kubefirst/cmd"
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/pkg"
"github.com/spf13/viper"
)
func main() {
now := time.Now()
epoch := now.Unix()
currentFolder, err := os.Getwd()
if err != nil {
stdLog.Panicf("unable to get current folder location, error is: %s", err)
}
logsFolder := fmt.Sprintf("%s/%s", currentFolder, "logs")
// we're ignoring folder creation handling at the moment
// todo: add folder creation handler
_ = os.Mkdir(logsFolder, 0700)
logfile := fmt.Sprintf("%s/log_%d.log", logsFolder, epoch)
//fmt.Printf("Logging at: %s \n", logfile)
// Avoid printing log helper for certain subcommands
var excludeLogHelperFrom []string = []string{"version"}
if len(os.Args) > 1 && !pkg.FindStringInSlice(excludeLogHelperFrom, os.Args[1]) {
fmt.Printf("\n-----------\n")
fmt.Printf("Follow your logs with: \n tail -f %s \n", logfile)
fmt.Printf("\n-----------\n")
}
file, err := pkg.OpenLogFile(logfile)
if err != nil {
stdLog.Panicf("unable to store log location, error is: %s", err)
}
// handle file close request
defer func(file *os.File) {
err = file.Close()
if err != nil {
log.Print(err)
}
}(file)
// setup default logging
// this Go standard log is active to keep compatibility with current code base
stdLog.SetOutput(file)
stdLog.SetPrefix("LOG: ")
stdLog.SetFlags(stdLog.Ldate | stdLog.Lmicroseconds | stdLog.Llongfile)
// setup Zerolog
log.Logger = pkg.ZerologSetup(file, zerolog.InfoLevel)
config := configs.ReadConfig()
// setup Viper (for non-local resources)
if err = pkg.SetupViper(config); err != nil {
stdLog.Panic(err)
}
viper.Set("logs-location", logsFolder)
err = viper.WriteConfig()
if err != nil {
stdLog.Panicf("unable to set log-file-location, error is: %s", err)
}
cmd.Execute()
}