1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-18 05:00:03 +02:00

src/main.go: adding "--log,-l" command line flag to enable file logging.

This commit is contained in:
Henrik Hautakoski 2020-06-26 14:01:14 +02:00
parent fe8724aae5
commit 9e8ee93983

View file

@ -2,6 +2,7 @@
package main
import (
"os"
"./log"
"./pid"
"github.com/pborman/getopt/v2"
@ -10,6 +11,7 @@ import (
// Command line flags
// ---------------------------------------------------------
var logFile string
var pidFile string
// argv_listen_addr
@ -36,14 +38,31 @@ func argv_listen_addr() string {
return addr
}
func openlog(file string) *os.File {
fd, err := os.OpenFile(logFile, os.O_APPEND | os.O_CREATE | os.O_WRONLY, 0644)
if err != nil {
log.Error(err.Error())
}
return fd
}
// main
// ---------------------------------------------------------
func main() {
var logfd *os.File
// Command line parsing
getopt.FlagLong(&logFile, "log", 'l', "Path to log file", "file")
getopt.FlagLong(&pidFile, "pid", 'p', "Path to pid file", "file")
getopt.Parse()
if len(logFile) > 0 {
logfd = openlog(logFile)
log.SetWriter(logfd)
}
log.Info("Process is starting with PID: %d", pid.Get())
if len(pidFile) > 0 {