mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-02 11:43:42 +02:00
src/main.go: adding "--log,-l" command line flag to enable file logging.
This commit is contained in:
parent
fe8724aae5
commit
9e8ee93983
1 changed files with 19 additions and 0 deletions
19
src/main.go
19
src/main.go
|
|
@ -2,6 +2,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"./log"
|
"./log"
|
||||||
"./pid"
|
"./pid"
|
||||||
"github.com/pborman/getopt/v2"
|
"github.com/pborman/getopt/v2"
|
||||||
|
|
@ -10,6 +11,7 @@ import (
|
||||||
// Command line flags
|
// Command line flags
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
|
var logFile string
|
||||||
var pidFile string
|
var pidFile string
|
||||||
|
|
||||||
// argv_listen_addr
|
// argv_listen_addr
|
||||||
|
|
@ -36,14 +38,31 @@ func argv_listen_addr() string {
|
||||||
return addr
|
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
|
// main
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
var logfd *os.File
|
||||||
|
|
||||||
// Command line parsing
|
// Command line parsing
|
||||||
|
getopt.FlagLong(&logFile, "log", 'l', "Path to log file", "file")
|
||||||
getopt.FlagLong(&pidFile, "pid", 'p', "Path to pid file", "file")
|
getopt.FlagLong(&pidFile, "pid", 'p', "Path to pid file", "file")
|
||||||
getopt.Parse()
|
getopt.Parse()
|
||||||
|
|
||||||
|
if len(logFile) > 0 {
|
||||||
|
logfd = openlog(logFile)
|
||||||
|
log.SetWriter(logfd)
|
||||||
|
}
|
||||||
|
|
||||||
log.Info("Process is starting with PID: %d", pid.Get())
|
log.Info("Process is starting with PID: %d", pid.Get())
|
||||||
|
|
||||||
if len(pidFile) > 0 {
|
if len(pidFile) > 0 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue