Skip to content

Commit

Permalink
[util] refs fibercrypto#298 - Add function to set log's output to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiD2ta committed Jan 18, 2020
1 parent a693890 commit 9b97156
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/util/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"io"
"io/ioutil"
"os"
"strings"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -77,3 +78,14 @@ func SetOutputTo(w io.Writer) {
func Disable() {
log.Out = ioutil.Discard
}

// SetOutputToFile sets the logger's outputs to a file with path <dir>
func SetOutputToFile(dir string) {
f, err := os.OpenFile(dir, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.WithError(err).Error("Error opening file: ", dir)
}
defer f.Close()

SetOutputTo(f)
}

0 comments on commit 9b97156

Please sign in to comment.