Skip to content

Commit

Permalink
Use os.TempDir to pick default location for log files.
Browse files Browse the repository at this point in the history
The previous code was a historical artifact.
  • Loading branch information
dsymonds committed Jul 18, 2013
1 parent 496d3b7 commit 029e58e
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions glog_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"os"
"os/user"
"path"
"path/filepath"
"strings"
"sync"
"time"
Expand All @@ -39,28 +38,13 @@ var logDirs []string

// If non-empty, overrides the choice of directory in which to write logs.
// See createLogDirs for the full list of possible destinations.
var log_dir = flag.String("log_dir", "", "If non-empty, write log files in this directory")
var logDir = flag.String("log_dir", "", "If non-empty, write log files in this directory")

func createLogDirs() {
candidates := []string{
*log_dir,

// Explicitly-supplied temp dirs
os.Getenv("TMPDIR"),
os.Getenv("TMP"),

// If all else fails
"/tmp",
}
for _, dir := range candidates {
if len(dir) == 0 {
continue
}
if !filepath.IsAbs(dir) {
dir = "/" + dir
}
logDirs = append(logDirs, dir)
if *logDir != "" {
logDirs = append(logDirs, *logDir)
}
logDirs = append(logDirs, os.TempDir())
}

var (
Expand Down

0 comments on commit 029e58e

Please sign in to comment.