Skip to content

Commit

Permalink
Removed deprecated 'rollingIntervalDaily'. (refs cihub#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodsign committed May 20, 2016
1 parent 8e70215 commit cedd97a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cfg_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions cfg_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
45 changes: 4 additions & 41 deletions writers_rollingfilewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion writers_rollingfilewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cedd97a

Please sign in to comment.