mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-06 19:07:50 +00:00
Deduplicate logfile opening code
This commit is contained in:
parent
8c2d6e92c2
commit
2fe21231fc
1 changed files with 17 additions and 8 deletions
|
|
@ -123,14 +123,9 @@ func (m *Command) SetupServer() error {
|
|||
m.Server.Cluster = cluster
|
||||
|
||||
// Setup logging output.
|
||||
if m.Config.LogPath == "" {
|
||||
m.Server.LogOutput = m.Stderr
|
||||
} else {
|
||||
logFile, err := os.OpenFile(m.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Server.LogOutput = logFile
|
||||
m.Server.LogOutput, err = GetLogWriter(m.Config.LogPath, m.Stderr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Configure holder.
|
||||
|
|
@ -203,6 +198,20 @@ func (m *Command) SetupServer() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetLogWriter opens a file for logging, or a default io.Writer (such as stderr) for an empty path.
|
||||
func GetLogWriter(path string, defaultWriter io.Writer) (io.Writer, error) {
|
||||
// This is split out so it can be used in NewServeCmd as well as SetupServer
|
||||
if path == "" {
|
||||
return defaultWriter, nil
|
||||
} else {
|
||||
logFile, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return logFile, nil
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeHost(host string) (string, error) {
|
||||
if !strings.Contains(host, ":") {
|
||||
host = host + ":"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue