Skip to content

Commit

Permalink
Merge pull request #25 from mkontani/fix/cmd-option
Browse files Browse the repository at this point in the history
fix flag
  • Loading branch information
maditya authored Sep 29, 2019

Verified

This commit was signed with the committer’s verified signature.
ZedThree Peter Hill
2 parents 25a21b2 + 18c8fef commit 4e2a93d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ import (
"google.golang.org/grpc/credentials"
)

const logFile = "/var/log/crypki/server.log"
const defaultLogFile = "/var/log/crypki/server.log"

// grpcHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC
// connections or otherHandler otherwise. More: https://grpc.io/blog/coreos
@@ -98,19 +98,14 @@ func getIPs() (ips []net.IP, err error) {
// Main represents the main function which starts crypki server.
func Main(keyP crypki.KeyIDProcessor) {
cfgVal := ""
logFile := ""
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

log.SetFlags(log.LstdFlags | log.Lshortfile)
file, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("failed to create log file: %v", err)
}
log.SetOutput(file)
go logRotate(file)

flag.StringVar(&cfgVal, "config", "", "Configuration file path")
flag.StringVar(&logFile, "logfile", defaultLogFile, "Log file path")
flag.Parse()

if cfgVal == "" {
log.Fatalf("no configuration file provided")
}
@@ -120,6 +115,14 @@ func Main(keyP crypki.KeyIDProcessor) {
log.Fatalf("invalid config: %v", err)
}

log.SetFlags(log.LstdFlags | log.Lshortfile)
file, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("failed to create log file: %v", err)
}
log.SetOutput(file)
go logRotate(file)

keyUsages := make(map[string]map[string]bool)
maxValidity := make(map[string]uint64)

0 comments on commit 4e2a93d

Please sign in to comment.