File tree 3 files changed +21
-9
lines changed
3 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -32,16 +32,16 @@ func (c *Config) WriteLog(s string) {
32
32
return
33
33
}
34
34
35
- if c .LogName == "" {
36
- c .LogName = logName ()
37
- d := filepath .Dir (c .LogName )
35
+ if c .LogName () == "" {
36
+ c .SetLog ()
37
+ d := filepath .Dir (c .LogName () )
38
38
_ , err := os .Stat (d )
39
39
if os .IsNotExist (err ) {
40
40
os .MkdirAll (d , 0755 )
41
41
}
42
42
}
43
43
44
- f , err1 := os .OpenFile (c .LogName , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
44
+ f , err1 := os .OpenFile (c .LogName () , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
45
45
if err1 != nil {
46
46
log .Fatalln (err1 )
47
47
}
@@ -85,7 +85,6 @@ func (c *Config) logHeader(logger *log.Logger) {
85
85
w .Flush ()
86
86
}
87
87
88
- // logName returns the full path to a new log file.
89
88
func logName () string {
90
89
const yyyymmddTime = "20060102150405"
91
90
filename := time .Now ().Format (yyyymmddTime ) + ".log"
Original file line number Diff line number Diff line change @@ -23,8 +23,7 @@ import (
23
23
24
24
type Config struct {
25
25
Dirs []string
26
- Save string
27
- LogName string
26
+ Save string // rename to SaveName
28
27
Dupes bool
29
28
Export bool
30
29
Log bool
@@ -39,6 +38,7 @@ type Config struct {
39
38
40
39
type internal struct {
41
40
test bool
41
+ log string
42
42
zips int
43
43
cmmts int
44
44
names int
@@ -48,14 +48,27 @@ type internal struct {
48
48
timer time.Time
49
49
}
50
50
51
+ // SetLog sets the full path to a new log file with a name based on the current date and time.
52
+ func (i * internal ) SetLog () {
53
+ i .log = logName ()
54
+ }
55
+
56
+ // SetTest toggles the unit test mode flag.
51
57
func (i * internal ) SetTest () {
52
58
i .test = true
53
59
}
54
60
61
+ // SetTimer initializes a timer for process time.
55
62
func (i * internal ) SetTimer () {
56
63
i .timer = time .Now ()
57
64
}
58
65
66
+ // SetLog returns the full path to the log file.
67
+ func (i * internal ) LogName () string {
68
+ return i .log
69
+ }
70
+
71
+ // Timer returns the time since the SetTimer was triggered.
59
72
func (i * internal ) Timer () time.Duration {
60
73
return time .Since (i .timer )
61
74
}
Original file line number Diff line number Diff line change @@ -83,8 +83,8 @@ func main() {
83
83
c .WalkDirs ()
84
84
// summaries
85
85
fmt .Println (c .Status ())
86
- if c .LogName != "" {
87
- fmt .Printf ("%s %s\n " , "The log is found at" , color .Primary .Sprint (c . LogName ))
86
+ if s := c .LogName (); s != "" {
87
+ fmt .Printf ("%s %s\n " , "The log is found at" , color .Primary .Sprint (s ))
88
88
}
89
89
}
90
90
You can’t perform that action at this time.
0 commit comments