Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
stat: customize log path
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoul committed Nov 8, 2018
1 parent cdefe7b commit 9464ebd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions statistics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# statistics
> Make statistics by gathering crypto info periodically
# Usage
- (Optional) Set log path `-logpath=[LOG_PATH]`
12 changes: 11 additions & 1 deletion statistics/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ var (
)

func init() {
logPath := "./report.log"
for _, val := range os.Args {
arg := strings.Split(val, "=")
if len(arg) < 2 {
continue
} else if arg[0] == "-logpath" {
logPath = arg[1]
}
}

// Initialize logger
logger = log.New()

Expand All @@ -30,7 +40,7 @@ func init() {
logger.Formatter = &log.JSONFormatter{
TimestampFormat: timestampFormat,
}
if f, err := os.OpenFile("./report.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666); err == nil {
if f, err := os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666); err == nil {
logger.Out = io.MultiWriter(f, os.Stdout)
} else {
fmt.Print("Failed to open log file: you can miss important log")
Expand Down

0 comments on commit 9464ebd

Please sign in to comment.