Skip to content

Commit 67427d6

Browse files
committed
Moved Log into internal.log feature.
1 parent 8ae3f4a commit 67427d6

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

lib/log.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ func (c *Config) WriteLog(s string) {
3232
return
3333
}
3434

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())
3838
_, err := os.Stat(d)
3939
if os.IsNotExist(err) {
4040
os.MkdirAll(d, 0755)
4141
}
4242
}
4343

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)
4545
if err1 != nil {
4646
log.Fatalln(err1)
4747
}
@@ -85,7 +85,6 @@ func (c *Config) logHeader(logger *log.Logger) {
8585
w.Flush()
8686
}
8787

88-
// logName returns the full path to a new log file.
8988
func logName() string {
9089
const yyyymmddTime = "20060102150405"
9190
filename := time.Now().Format(yyyymmddTime) + ".log"

lib/zipcmt.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323

2424
type Config struct {
2525
Dirs []string
26-
Save string
27-
LogName string
26+
Save string // rename to SaveName
2827
Dupes bool
2928
Export bool
3029
Log bool
@@ -39,6 +38,7 @@ type Config struct {
3938

4039
type internal struct {
4140
test bool
41+
log string
4242
zips int
4343
cmmts int
4444
names int
@@ -48,14 +48,27 @@ type internal struct {
4848
timer time.Time
4949
}
5050

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.
5157
func (i *internal) SetTest() {
5258
i.test = true
5359
}
5460

61+
// SetTimer initializes a timer for process time.
5562
func (i *internal) SetTimer() {
5663
i.timer = time.Now()
5764
}
5865

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.
5972
func (i *internal) Timer() time.Duration {
6073
return time.Since(i.timer)
6174
}

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func main() {
8383
c.WalkDirs()
8484
// summaries
8585
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))
8888
}
8989
}
9090

0 commit comments

Comments
 (0)