Skip to content

Commit

Permalink
HEIMDALL-5818 Add log rolling to OEC Windows service (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
metehanozturk authored Mar 24, 2021
1 parent ce55d52 commit b162854
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
env:
CGO_ENABLED: 0
GOOS: windows
GOARCH: 386
GOARCH: amd64
GO111MODULE: on

- name: Build Win 64
Expand Down
19 changes: 15 additions & 4 deletions windows_service/main/oecService.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/kardianos/service"
"gopkg.in/natefinch/lumberjack.v2"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -50,8 +51,13 @@ func (p *Program) run() {
p.service.Stop()
return
}
defer stderr.Close()
p.cmd.Stderr = stderr
stderr.Close()
p.cmd.Stderr = &lumberjack.Logger{
Filename: p.Stderr,
MaxSize: 10, // MB
MaxAge: 10, // Days
LocalTime: true,
}
}
if p.Stdout != "" {
stdout, err := os.OpenFile(p.Stdout, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0777)
Expand All @@ -60,8 +66,13 @@ func (p *Program) run() {
p.service.Stop()
return
}
defer stdout.Close()
p.cmd.Stdout = stdout
stdout.Close()
p.cmd.Stdout = &lumberjack.Logger{
Filename: p.Stdout,
MaxSize: 10, // MB
MaxAge: 10, // Days
LocalTime: true,
}
}

err := p.cmd.Run()
Expand Down

0 comments on commit b162854

Please sign in to comment.