diff --git a/cfg_parser.go b/cfg_parser.go index a521f7b..a7ba6ba 100644 --- a/cfg_parser.go +++ b/cfg_parser.go @@ -1115,7 +1115,7 @@ func createRollingFileWriter(node *xmlNode, formatFromParent *formatter, formats return nil, newMissingArgumentError(node.name, rollingFileDataPatternAttr) } - rollingWriter, err := NewRollingFileWriterTime(path, rArchiveType, rArchivePath, maxRolls, dataPattern, rollingIntervalAny, nameMode, rArchiveExploded) + rollingWriter, err := NewRollingFileWriterTime(path, rArchiveType, rArchivePath, maxRolls, dataPattern, nameMode, rArchiveExploded) if err != nil { return nil, err } diff --git a/cfg_parser_test.go b/cfg_parser_test.go index 0d4d969..23e4cf6 100644 --- a/cfg_parser_test.go +++ b/cfg_parser_test.go @@ -388,7 +388,7 @@ func getParserTests() []parserTest { testExpected = new(configForParsing) testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriterTime, _ := NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalAny, rollingNameModePostfix, false) + testrollingFileWriterTime, _ := NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingNameModePostfix, false) testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testrollingFileWriterTime}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter @@ -407,7 +407,7 @@ func getParserTests() []parserTest { testExpected = new(configForParsing) testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriterTime, _ = NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalDaily, rollingNameModePostfix, false) + testrollingFileWriterTime, _ = NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingNameModePostfix, false) testbufferedWriter, _ := NewBufferedWriter(testrollingFileWriterTime, 100500, 100) testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testbufferedWriter}) testExpected.LogType = syncloggerTypeFromString @@ -1064,7 +1064,7 @@ func getParserTests() []parserTest { testExpected = new(configForParsing) testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriterTime, _ = NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalDaily, rollingNameModePrefix, false) + testrollingFileWriterTime, _ = NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingNameModePrefix, false) testbufferedWriter, _ = NewBufferedWriter(testrollingFileWriterTime, 100500, 100) testFormat, _ = NewFormatter("%Level %Msg %File 123") formattedWriter, _ = NewFormattedWriter(testbufferedWriter, testFormat) diff --git a/writers_rollingfilewriter.go b/writers_rollingfilewriter.go index b16886a..cfa9233 100644 --- a/writers_rollingfilewriter.go +++ b/writers_rollingfilewriter.go @@ -72,27 +72,6 @@ func rollingNameModeFromString(rollingNameStr string) (rollingNameMode, bool) { return 0, false } -type rollingIntervalType uint8 - -const ( - rollingIntervalAny = iota - rollingIntervalDaily -) - -var rollingInvervalTypesStringRepresentation = map[rollingIntervalType]string{ - rollingIntervalDaily: "daily", -} - -func rollingIntervalTypeFromString(rollingTypeStr string) (rollingIntervalType, bool) { - for tp, tpStr := range rollingInvervalTypesStringRepresentation { - if tpStr == rollingTypeStr { - return tp, true - } - } - - return 0, false -} - var rollingTypesStringRepresentation = map[rollingType]string{ rollingTypeSize: "size", rollingTypeTime: "date", @@ -621,18 +600,17 @@ func (rws *rollingFileWriterSize) String() string { type rollingFileWriterTime struct { *rollingFileWriter timePattern string - interval rollingIntervalType currentTimeFileName string } func NewRollingFileWriterTime(fpath string, atype rollingArchiveType, apath string, maxr int, - timePattern string, interval rollingIntervalType, namemode rollingNameMode, archiveExploded bool) (*rollingFileWriterTime, error) { + timePattern string, namemode rollingNameMode, archiveExploded bool) (*rollingFileWriterTime, error) { rw, err := newRollingFileWriter(fpath, rollingTypeTime, atype, apath, maxr, namemode, archiveExploded) if err != nil { return nil, err } - rws := &rollingFileWriterTime{rw, timePattern, interval, ""} + rws := &rollingFileWriterTime{rw, timePattern, ""} rws.self = rws return rws, nil } @@ -648,21 +626,7 @@ func (rwt *rollingFileWriterTime) needsToRoll() (bool, error) { return false, nil } } - if rwt.interval == rollingIntervalAny { - return true, nil - } - - tprev, err := time.ParseInLocation(rwt.timePattern, rwt.getFileRollName(rwt.fileName), time.Local) - if err != nil { - return false, err - } - - diff := time.Now().Sub(tprev) - switch rwt.interval { - case rollingIntervalDaily: - return diff >= 24*time.Hour, nil - } - return false, fmt.Errorf("unknown interval type: %d", rwt.interval) + return true, nil } func (rwt *rollingFileWriterTime) isFileRollNameValid(rname string) bool { @@ -723,11 +687,10 @@ func (rwt *rollingFileWriterTime) getCurrentModifiedFileName(originalFileName st } func (rwt *rollingFileWriterTime) String() string { - return fmt.Sprintf("Rolling file writer (By TIME): filename: %s, archive: %s, archivefile: %s, maxInterval: %v, pattern: %s, maxRolls: %v", + return fmt.Sprintf("Rolling file writer (By TIME): filename: %s, archive: %s, archivefile: %s, pattern: %s, maxRolls: %v", rwt.fileName, rollingArchiveTypesStringRepresentation[rwt.archiveType], rwt.archivePath, - rwt.interval, rwt.timePattern, rwt.maxRolls) } diff --git a/writers_rollingfilewriter_test.go b/writers_rollingfilewriter_test.go index df8a94b..02fd8ab 100644 --- a/writers_rollingfilewriter_test.go +++ b/writers_rollingfilewriter_test.go @@ -82,7 +82,7 @@ func rollingFileWriterGetter(testCase *fileWriterTestCase) (io.WriteCloser, erro if testCase.rollingType == rollingTypeSize { return NewRollingFileWriterSize(testCase.fileName, testCase.archiveType, testCase.archivePath, testCase.fileSize, testCase.maxRolls, testCase.nameMode, testCase.archiveExploded) } else if testCase.rollingType == rollingTypeTime { - return NewRollingFileWriterTime(testCase.fileName, testCase.archiveType, testCase.archivePath, -1, testCase.datePattern, rollingIntervalDaily, testCase.nameMode, testCase.archiveExploded) + return NewRollingFileWriterTime(testCase.fileName, testCase.archiveType, testCase.archivePath, -1, testCase.datePattern, testCase.nameMode, testCase.archiveExploded) } return nil, fmt.Errorf("incorrect rollingType")