const backupTimeFormat … const compressSuffix … const defaultMaxSize … var _ … type Logger … var currentTime … var osStat … var megabyte … // Write implements io.Writer. If a write would cause the log file to be larger // than MaxSize, the file is closed, renamed to include a timestamp of the // current time, and a new log file is created using the original log file name. // If the length of the write is greater than MaxSize, an error is returned. func (l *Logger) Write(p []byte) (n int, err error) { … } // Close implements io.Closer, and closes the current logfile. func (l *Logger) Close() error { … } // close closes the file if it is open. func (l *Logger) close() error { … } // Rotate causes Logger to close the existing log file and immediately create a // new one. This is a helper function for applications that want to initiate // rotations outside of the normal rotation rules, such as in response to // SIGHUP. After rotating, this initiates compression and removal of old log // files according to the configuration. func (l *Logger) Rotate() error { … } // rotate closes the current file, moves it aside with a timestamp in the name, // (if it exists), opens a new file with the original filename, and then runs // post-rotation processing and removal. func (l *Logger) rotate() error { … } // openNew opens a new log file for writing, moving any old log file out of the // way. This methods assumes the file has already been closed. func (l *Logger) openNew() error { … } // backupName creates a new filename from the given name, inserting a timestamp // between the filename and the extension, using the local time if requested // (otherwise UTC). func backupName(name string, local bool) string { … } // openExistingOrNew opens the logfile if it exists and if the current write // would not put it over MaxSize. If there is no such file or the write would // put it over the MaxSize, a new file is created. func (l *Logger) openExistingOrNew(writeLen int) error { … } // filename generates the name of the logfile from the current time. func (l *Logger) filename() string { … } // millRunOnce performs compression and removal of stale log files. // Log files are compressed if enabled via configuration and old log // files are removed, keeping at most l.MaxBackups files, as long as // none of them are older than MaxAge. func (l *Logger) millRunOnce() error { … } // millRun runs in a goroutine to manage post-rotation compression and removal // of old log files. func (l *Logger) millRun() { … } // mill performs post-rotation compression and removal of stale log files, // starting the mill goroutine if necessary. func (l *Logger) mill() { … } // oldLogFiles returns the list of backup log files stored in the same // directory as the current log file, sorted by ModTime func (l *Logger) oldLogFiles() ([]logInfo, error) { … } // timeFromName extracts the formatted time from the filename by stripping off // the filename's prefix and extension. This prevents someone's filename from // confusing time.parse. func (l *Logger) timeFromName(filename, prefix, ext string) (time.Time, error) { … } // max returns the maximum size in bytes of log files before rolling. func (l *Logger) max() int64 { … } // dir returns the directory for the current filename. func (l *Logger) dir() string { … } // prefixAndExt returns the filename part and extension part from the Logger's // filename. func (l *Logger) prefixAndExt() (prefix, ext string) { … } // compressLogFile compresses the given log file, removing the // uncompressed log file if successful. func compressLogFile(src, dst string) (err error) { … } type logInfo … type byFormatTime … func (b byFormatTime) Less(i, j int) bool { … } func (b byFormatTime) Swap(i, j int) { … } func (b byFormatTime) Len() int { … }