This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
forked from jdel/go-syno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
69 lines (54 loc) · 1.63 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package syno // import jdel.org/go-syno/syno
import (
"io"
"path/filepath"
log "github.com/sirupsen/logrus"
)
// LogPanicLevel is a shorthand for logrus.PanicLevel
var LogPanicLevel = func() log.Level { return log.PanicLevel }()
// LogFatalLevel is a shorthand for logrus.FatalLevel
var LogFatalLevel = func() log.Level { return log.FatalLevel }()
// LogErrorLevel is a shorthand for logrus.ErrorLevel
var LogErrorLevel = func() log.Level { return log.ErrorLevel }()
// LogWarnLevel is a shorthand for logrus.WarnLevel
var LogWarnLevel = func() log.Level { return log.WarnLevel }()
// LogInfoLevel is a shorthand for logrus.InfoLevel
var LogInfoLevel = func() log.Level { return log.InfoLevel }()
// LogDebugLevel is a shorthand for logrus.DebugLevel
var LogDebugLevel = func() log.Level { return log.DebugLevel }()
// Options holds external context
type Options struct {
PackagesDir string
CacheDir string
ModelsFile string
Language string
MD5 bool
}
var o Options
func init() {
// Default options
o = Options{
PackagesDir: filepath.Join(executablePath(), "packages"),
CacheDir: filepath.Join(executablePath(), "cache"),
ModelsFile: filepath.Join(executablePath(), "models.yml"),
Language: "enu",
}
log.SetLevel(log.ErrorLevel)
}
// SetLogLevel sets the logrus log level
func SetLogLevel(l log.Level) {
log.SetLevel(l)
}
// SetLogOutput sets the logrus log output
func SetLogOutput(i io.Writer) {
log.SetOutput(i)
}
// SetOptions sets global options
func SetOptions(opt Options) {
log.Debug("Overriding default options")
o = opt
}
// GetOptions returns global options
func GetOptions() *Options {
return &o
}