func (logger *ConsoleLogger) log() { var record *Record var file *os.File var items []interface{} var status string var write bool for { select { case record = <-logger.receiver: items = record.Items write = true for _, filter := range ConsoleFilters { write, data := filter(record) if !write { break } if data != nil { items = data break } } if !write { continue } argLength := len(items) if record.Error { file = os.Stderr } else { file = os.Stdout } if record.Error { status = "ERR" } else { status = "INF" } fmt.Fprintf(file, "%s [%s-%s-%s %s:%s:%s]", status, encoding.PadInt64(UTC.Year, 4), encoding.PadInt(UTC.Month, 2), encoding.PadInt(UTC.Day, 2), encoding.PadInt(UTC.Hour, 2), encoding.PadInt(UTC.Minute, 2), encoding.PadInt(UTC.Second, 2)) for i := 0; i < argLength; i++ { fmt.Fprintf(file, " %v", items[i]) } file.Write([]byte("\n")) case <-checker: if len(logger.receiver) > 0 { checker <- 1 continue } waiter <- 1 } } }
func (logger *FileLogger) GetFilename(timestamp *time.Time) string { var suffix string switch logger.rotate { case RotateNever: suffix = "" case RotateDaily: suffix = "." + encoding.PadInt64(timestamp.Year, 4) + "-" + encoding.PadInt(timestamp.Month, 2) + "-" + encoding.PadInt(timestamp.Day, 2) case RotateHourly: suffix = "." + encoding.PadInt64(timestamp.Year, 4) + "-" + encoding.PadInt(timestamp.Month, 2) + "-" + encoding.PadInt(timestamp.Day, 2) + "." + encoding.PadInt(timestamp.Hour, 2) case RotateTest: suffix = "." + encoding.PadInt64(timestamp.Year, 4) + "-" + encoding.PadInt(timestamp.Month, 2) + "-" + encoding.PadInt(timestamp.Day, 2) + "." + encoding.PadInt(timestamp.Hour, 2) + "-" + encoding.PadInt(timestamp.Minute, 2) + "-" + encoding.PadInt(timestamp.Second, 2) } filename := logger.name + suffix + ".log" return path.Join(logger.directory, filename) }
func (logger *ConsoleLogger) log() { var record *Record var file *os.File var items []interface{} var prefix, status string var prefixErr, prefixInfo string var suffix []byte var write bool if colorify { prefixErr = fmt.Sprintf("\x1b[%sm", colors["error"]) prefixInfo = fmt.Sprintf("\x1b[%sm", colors["info"]) suffix = []byte("\x1b[0m\n") } else { suffix = []byte{'\n'} } for { select { case record = <-logger.receiver: items = record.Items write = true if filter, present := ConsoleFilters[record.Type]; present { write, items = filter(items) if !write || items == nil { continue } } if record.Error { file = os.Stderr } else { file = os.Stdout } if record.Error { prefix = prefixErr status = " ERROR:" } else { prefix = prefixInfo status = "" } mutex.RLock() year, month, day := now.Date() hour, minute, second := now.Clock() mutex.RUnlock() fmt.Fprintf(file, "%s[%s-%s-%s %s:%s:%s]%s", prefix, encoding.PadInt(year, 4), encoding.PadInt(int(month), 2), encoding.PadInt(day, 2), encoding.PadInt(hour, 2), encoding.PadInt(minute, 2), encoding.PadInt(second, 2), status) for _, item := range items { fmt.Fprintf(file, " %v", item) } file.Write(suffix) case <-checker: if len(logger.receiver) > 0 { checker <- 1 continue } waiter <- 1 } } }