mirror of
https://gitee.com/goploy/goploy.git
synced 2024-11-30 03:07:59 +08:00
A log stdout
This commit is contained in:
parent
3fc1be6f25
commit
555410a9f9
@ -3,7 +3,7 @@ DB_CONN=root:xxxxxx@tcp(127.0.0.1:3306)/goploy?charset=utf8mb4,utf8
|
||||
# password sign key
|
||||
SIGN_KEY=xxxxxxxxxxxxxx
|
||||
# sync log path
|
||||
LOG_PATH=./tmp/
|
||||
LOG_PATH=stdout
|
||||
# rysnc and ssh key
|
||||
SSHKEY_PATH=~/.ssh/id_rsa
|
||||
# deploy enviorment
|
||||
|
15
core/Log.go
15
core/Log.go
@ -2,9 +2,11 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -21,7 +23,12 @@ const (
|
||||
|
||||
// Log information to file with logged day
|
||||
func Log(lv LogLevel, content string) {
|
||||
logPath, err := filepath.Abs(os.Getenv("LOG_PATH"))
|
||||
var logFile io.Writer
|
||||
logPathEnv := os.Getenv("LOG_PATH")
|
||||
if strings.ToLower(logPathEnv) == "stdout" {
|
||||
logFile = os.Stdout
|
||||
} else {
|
||||
logPath, err := filepath.Abs(logPathEnv)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
@ -32,10 +39,12 @@ func Log(lv LogLevel, content string) {
|
||||
}
|
||||
}
|
||||
file := logPath + "/" + time.Now().Format("20060102") + ".log"
|
||||
logFile, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
|
||||
logFile, err = os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
|
||||
if nil != err {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
logger := log.New(logFile, string(lv), log.LstdFlags|log.Llongfile)
|
||||
}
|
||||
|
||||
logger := log.New(logFile, string(lv), log.LstdFlags|log.Lshortfile)
|
||||
logger.Output(2, content)
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -185,14 +185,14 @@ func install() {
|
||||
if len(mysqlPort) == 0 {
|
||||
mysqlPort = "3306"
|
||||
}
|
||||
println("Please enter the absolute path of the log directory(default /tmp/):")
|
||||
println("Please enter the absolute path of the log directory(default stdout):")
|
||||
logPath, err := inputReader.ReadString('\n')
|
||||
if err != nil {
|
||||
panic("There were errors reading, exiting program.")
|
||||
}
|
||||
logPath = utils.ClearNewline(logPath)
|
||||
if len(logPath) == 0 {
|
||||
logPath = "/tmp/"
|
||||
logPath = "stdout"
|
||||
}
|
||||
println("Please enter the listening port(default 80):")
|
||||
port, err := inputReader.ReadString('\n')
|
||||
|
Loading…
Reference in New Issue
Block a user