Skip to content

Commit 029e58e

Browse files
committed
Use os.TempDir to pick default location for log files.
The previous code was a historical artifact.
1 parent 496d3b7 commit 029e58e

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

glog_file.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"os"
2626
"os/user"
2727
"path"
28-
"path/filepath"
2928
"strings"
3029
"sync"
3130
"time"
@@ -39,28 +38,13 @@ var logDirs []string
3938

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

4443
func createLogDirs() {
45-
candidates := []string{
46-
*log_dir,
47-
48-
// Explicitly-supplied temp dirs
49-
os.Getenv("TMPDIR"),
50-
os.Getenv("TMP"),
51-
52-
// If all else fails
53-
"/tmp",
54-
}
55-
for _, dir := range candidates {
56-
if len(dir) == 0 {
57-
continue
58-
}
59-
if !filepath.IsAbs(dir) {
60-
dir = "/" + dir
61-
}
62-
logDirs = append(logDirs, dir)
44+
if *logDir != "" {
45+
logDirs = append(logDirs, *logDir)
6346
}
47+
logDirs = append(logDirs, os.TempDir())
6448
}
6549

6650
var (

0 commit comments

Comments
 (0)