新增日志输出至本地文件 app.log
This commit is contained in:
@ -11,7 +11,9 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger.LogInit()
|
||||
file, _ := os.OpenFile("./app.log", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644)
|
||||
defer file.Close()
|
||||
logger.LogInit(file)
|
||||
|
||||
var conf Config.Object
|
||||
if len(os.Args) == 1 || os.Args[1][0] == '-' {
|
||||
|
||||
@ -23,12 +23,12 @@ var (
|
||||
Warning *log.Logger
|
||||
)
|
||||
|
||||
func LogInit() {
|
||||
log.SetOutput(os.Stdout)
|
||||
func LogInit(file *os.File) {
|
||||
log.SetOutput(file)
|
||||
log.SetFlags(log.Ldate | log.Ltime)
|
||||
log.SetPrefix(fmt.Sprintf("%s[INFO]%s ", Cyan, Reset))
|
||||
|
||||
Success = log.New(os.Stdout, fmt.Sprintf("%s[SUCCESS]%s ", Green, Reset), log.Ldate|log.Ltime)
|
||||
Error = log.New(os.Stdout, fmt.Sprintf("%s[ERROR]%s ", Red, Reset), log.Ldate|log.Ltime)
|
||||
Warning = log.New(os.Stdout, fmt.Sprintf("%s[WARNING]%s ", Yellow, Reset), log.Ldate|log.Ltime)
|
||||
Success = log.New(file, fmt.Sprintf("%s[SUCCESS]%s ", Green, Reset), log.Ldate|log.Ltime)
|
||||
Error = log.New(file, fmt.Sprintf("%s[ERROR]%s ", Red, Reset), log.Ldate|log.Ltime)
|
||||
Warning = log.New(file, fmt.Sprintf("%s[WARNING]%s ", Yellow, Reset), log.Ldate|log.Ltime)
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ func (config *Object) CheckFile() {
|
||||
log.Printf("配置检查完毕,请检查相关配置后重新运行!")
|
||||
os.Exit(0)
|
||||
}
|
||||
log.Printf("配置检查完毕,即将开始更新证书!")
|
||||
log.Printf("配置检查完毕,即将开始检查证书相关内容!")
|
||||
}
|
||||
|
||||
func (config *Object) CheckCommand() {
|
||||
@ -103,5 +103,5 @@ func (config *Object) CheckCommand() {
|
||||
log.Printf("配置检查完毕,请检查相关配置后重新运行!")
|
||||
os.Exit(0)
|
||||
}
|
||||
log.Printf("配置检查完毕,即将开始更新证书!")
|
||||
log.Printf("配置检查完毕,即将开始检查证书相关内容!")
|
||||
}
|
||||
|
||||
21
main.go
21
main.go
@ -1,21 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
//TIP <p>To run your code, right-click the code and select <b>Run</b>.</p> <p>Alternatively, click
|
||||
// the <icon src="AllIcons.Actions.Execute"/> icon in the gutter and select the <b>Run</b> menu item from here.</p>
|
||||
|
||||
func main() {
|
||||
//TIP <p>Press <shortcut actionId="ShowIntentionActions"/> when your caret is at the underlined text
|
||||
// to see how GoLand suggests fixing the warning.</p><p>Alternatively, if available, click the lightbulb to view possible fixes.</p>
|
||||
s := "gopher"
|
||||
fmt.Printf("Hello and welcome, %s!\n", s)
|
||||
|
||||
for i := 1; i <= 5; i++ {
|
||||
//TIP <p>To start your debugging session, right-click your code in the editor and select the Debug option.</p> <p>We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.</p>
|
||||
fmt.Println("i =", 100/i)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user