glogutils

package module
v0.0.0-...-4b2fd81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

README

Build Status

Rationale

Google logging library is a wonderful lib:

https://github.com/golang/glog

However the logs that it generates are never deleted.

glogutils adds one function to cleanup logs:

glogutils.CleanupLogs() //Deletes files that are no longer active

and another one to understand if google logging logs to dir:

glogutils.LogDir() // returns "" if log dir was not specified

Example

// This function starts cleaning up after glog library, periodically removing logs
// that are no longer used
func startLogsCleanup(period time.Duration) error {
	if glogutils.LogDir() != "" {
		glog.Infof("Starting log cleanup go routine with period: %s", period)
		go func() {
			t := time.Tick(period)
			for {
				select {
				case <-t:
					glog.Infof("Start cleaning up the logs")
					err := glogutils.CleanupLogs()
					if err != nil {
						glog.Errorf("Failed to clean up the logs: %s", err)
						return
					}
				}
			}
		}()
	}
	return nil
}

License

Apache2

Documentation

Index

Constants

View Source
const DEFAULT_LOGMAXAGE = 0 // default max age in days

Variables

This section is empty.

Functions

func CleanupLogs

func CleanupLogs() error

Removes old logs generated by golang, should be called in some separate goroutine

func LogDir

func LogDir() string

Determines whether golang's log_dir has been set without overriding it

func LogMaxAge

func LogMaxAge() int

Determines whether log_max_age has been set without overriding it. LogMaxAge is the maximum # of days (exclusive) to retain old files based on the timestamp encoded in their filename. log_max_age <= 0 means delete immediately

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL