func (fa *fileAppender) getLogChunks() (*gorivets.SortedSlice, int64) { archiveName, _ := filepath.Abs(fa.fileName) nameRegExp := archiveName + "\\.\\d+" if fa.rotate == rsDaily { nameRegExp = archiveName + "\\.\\d{4}-\\d{2}-\\d{2}\\.\\d+" } dir := filepath.Dir(archiveName) fileInfos, _ := ioutil.ReadDir(dir) chunks, _ := gorivets.NewSortedSlice(5) var size int64 = 0 for _, fInfo := range fileInfos { if m, _ := regexp.MatchString(nameRegExp, fInfo.Name()); fInfo.IsDir() || !m { continue } idx := strings.LastIndex(fInfo.Name(), ".") if idx < 0 { continue } fId, err := strconv.Atoi(fInfo.Name()[idx+1:]) if err != nil { continue } chunks.Add(&chunkInfo{fId, fInfo.Name(), fInfo.Size()}) size += fInfo.Size() } return chunks, size }
func (s *logLevelSettingSuite) TestSetLogLevel(c *C) { ss, _ := gorivets.NewSortedSlice(2) setLogLevel(INFO, "a.b", ss) setLogLevel(INFO, "a", ss) setLogLevel(INFO, "b", ss) c.Assert(ss.Len(), Equals, 3) c.Assert(ss.At(0).(*logLevelSetting).loggerName, Equals, "a") c.Assert(ss.At(1).(*logLevelSetting).loggerName, Equals, "a.b") c.Assert(ss.At(2).(*logLevelSetting).loggerName, Equals, "b") }
func newLogConfig() *logConfig { lc := &logConfig{} lc.loggers = make(map[string]*logger) lc.logLevels, _ = gorivets.NewSortedSlice(10) lc.logContexts, _ = gorivets.NewSortedSlice(2) lc.appenderFactorys = make(map[string]AppenderFactory) lc.appenders = make(map[string]Appender) lc.levelNames = make([]string, ALL+1) lc.levelMap = make(map[string]Level) lc.levelNames[FATAL] = "FATAL" lc.levelNames[ERROR] = "ERROR" lc.levelNames[WARN] = "WARN " lc.levelNames[INFO] = "INFO " lc.levelNames[DEBUG] = "DEBUG" lc.levelNames[TRACE] = "TRACE" lc.levelNames[ALL] = "ALL " return lc }
func (s *logContextSuite) TestGetLogLevelContext(c *C) { ss, _ := gorivets.NewSortedSlice(2) c.Assert(getLogLevelContext("a", ss), IsNil) appenders := make([]Appender, 1, 10) appenders[0] = s lc, _ := newLogContext("b", appenders, true, true, 1) ss.Add(lc) c.Assert(getLogLevelContext("a", ss), IsNil) c.Assert(getLogLevelContext("b", ss), Equals, lc) lc, _ = newLogContext("", appenders, true, true, 1) ss.Add(lc) c.Assert(getLogLevelContext("a", ss).loggerName, Equals, "") c.Assert(getLogLevelContext("b", ss).loggerName, Equals, "b") }
func (s *logLevelSettingSuite) TestGetSetLogLevel(c *C) { ss, _ := gorivets.NewSortedSlice(2) c.Assert(getLogLevelSetting("a", ss), IsNil) setLogLevel(INFO, "b", ss) c.Assert(getLogLevelSetting("a", ss), IsNil) setLogLevel(INFO, "", ss) c.Assert(getLogLevelSetting("a", ss).loggerName, Equals, "") setLogLevel(INFO, "b.d", ss) setLogLevel(INFO, "b.d.e", ss) setLogLevel(INFO, "b.d.e.g", ss) c.Assert(getLogLevelSetting("b.d.a", ss).loggerName, Equals, "b.d") c.Assert(getLogLevelSetting("b.d.e.f", ss).loggerName, Equals, "b.d.e") c.Assert(getLogLevelSetting("b.d.e.g", ss).loggerName, Equals, "b.d.e.g") }
func (s *nameUtilsSuite) TestGetSetLogLevel(c *C) { ss, _ := gorivets.NewSortedSlice(2) c.Assert(getNearestAncestor(&nameUtilsSuite{"a"}, ss), IsNil) ss.Add(&nameUtilsSuite{"b"}) c.Assert(getNearestAncestor(&nameUtilsSuite{"a"}, ss), IsNil) ss.Add(&nameUtilsSuite{""}) c.Assert(getNearestAncestor(&nameUtilsSuite{"a"}, ss).(*nameUtilsSuite).loggerName, Equals, "") ss.Add(&nameUtilsSuite{"a.b.c"}) ss.Add(&nameUtilsSuite{"a.b"}) ss.Add(&nameUtilsSuite{"a"}) c.Assert(getNearestAncestor(&nameUtilsSuite{"a.b.d"}, ss).(*nameUtilsSuite).loggerName, Equals, "a.b") c.Assert(getNearestAncestor(&nameUtilsSuite{"a.b.c"}, ss).(*nameUtilsSuite).loggerName, Equals, "a.b.c") c.Assert(getNearestAncestor(&nameUtilsSuite{"a.b.c.d"}, ss).(*nameUtilsSuite).loggerName, Equals, "a.b.c") c.Assert(getNearestAncestor(&nameUtilsSuite{"a.b.c.d"}, ss).(*nameUtilsSuite).loggerName, Equals, "a.b.c") c.Assert(getNearestAncestor(&nameUtilsSuite{"a.bc.d"}, ss).(*nameUtilsSuite).loggerName, Equals, "a") }