Skip to content

Commit 5ababfd

Browse files
committed
fix: removes the redundant date updating goroutine
1 parent 8d6b3a5 commit 5ababfd

2 files changed

Lines changed: 8 additions & 23 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Compatible with Go version 1.18.x and above
2525
/******************** Basic Logging methods usage ********************/
2626
logger := logs.NewLogger()
2727
logger.Warn("my warning test") // stdout: 'WARN: my warning test'
28-
logger.Info("my", "into", "test", 2) // stdout: 'INFO: my info test 2'
28+
logger.Info("my", "info", "test", 2) // stdout: 'INFO: my info test 2'
2929
logger.Debug("hey", "check this", "debug") // stdout: 'DEBUG: hey check this debug'
3030
logger.Error("here is the error") // stderr: 'ERROR: here is the error'
3131

@@ -36,13 +36,13 @@ logger := logs.NewLogger().
3636
AddTime(true).
3737
AddDate(true)
3838

39-
logger.Warn("This is my Warn log", "Test arg") // stdout: WARN[03/11/2024 18:35:43]: This is my Warn log Test arg
39+
logger.Warn("This is my Warn log") // stdout: WARN[03/11/2024 18:35:43]: This is my Warn log
4040

4141
logger.SetEncoder(shared.JsonEncoderType)
42-
logger.Debug("This is my Debug log", "Test arg") // stdout: {"level":"DEBUG","date":"03/11/2024","time":"18:35:43","message":"This is my Debug log Test arg"}
42+
logger.Debug("This is my Debug log") // stdout: {"level":"DEBUG","datetime":"03/11/2024 18:35:43","message":"This is my Debug log"}
4343

4444
logger.AddTime(false)
45-
logger.Debug("This is my Debug log", "Test arg") // stdout: {"level":"DEBUG","date":"03/11/2024","message":"This is my Debug log Test second arg"}
45+
logger.Debug("This is my Debug log") // stdout: {"level":"DEBUG","date":"03/11/2024","message":"This is my Debug log"}
4646

4747
/******************** Logging to a file example ********************/
4848
file, err := os.OpenFile("./my-out-file.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
@@ -100,7 +100,7 @@ Contributions are welcome, Here's how you can help:
100100
- **Testing**
101101
- Run tests: `make test`
102102
- Run benchmarks: `make test-benchmark`
103-
- Ensure test coverage remains high, it can be checked using `make test-coverage`
103+
- Ensure test coverage remains high; it can be checked using `make test-coverage`
104104

105105
## 📝 License
106106

internal/services/datetime_printer.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ func (d *DateTimePrinter) init() {
6464
d.cachedTimes[i].Store(now.Format(timeFormat[fmt]))
6565
}
6666

67-
go d.loopUpdateDate()
68-
go d.loopUpdateTime()
67+
go d.loopUpdateDateTime()
6968
}
7069

71-
// loopUpdateTime updates all time formats, the unix timestamp every second,
70+
// loopUpdateDateTime updates all time formats, the unix timestamp every second,
7271
// and refreshes the date format if the day has changed.
73-
func (d *DateTimePrinter) loopUpdateTime() {
72+
func (d *DateTimePrinter) loopUpdateDateTime() {
7473
// Initialize lastDay with a value that forces an update on the first iteration
7574
lastDay := -1
7675

@@ -101,20 +100,6 @@ func (d *DateTimePrinter) loopUpdateTime() {
101100
}
102101
}
103102

104-
// loopUpdateDate updates all date formats every 10 mins
105-
func (d *DateTimePrinter) loopUpdateDate() {
106-
for {
107-
now := d.timeNow()
108-
109-
for i := 0; i < 3; i++ {
110-
fmt := s.DateTimeFormat(i)
111-
d.cachedDates[i].Store(now.Format(dateFormat[fmt]))
112-
}
113-
114-
time.Sleep(time.Minute * 10)
115-
}
116-
}
117-
118103
// GetDateTimePrinter returns the singleton instance.
119104
func GetDateTimePrinter() *DateTimePrinter {
120105
dateTimePrinterOnce.Do(

0 commit comments

Comments
 (0)