This library is used to standardized log message for Runsystem service. You can use this library to simplify your service logging setup.
You can run this in your terminal
go get -u github.com/runsystemid/gologImport this library in your main function or bootstrap function.
import "github.com/runsystemid/golog"There some required configs. Make sure to initialize the values first. Best practice is to put the values in config files to make it easier to update.
| Config | Description |
|---|---|
| App | Application name |
| AppVer | Application version |
| Env | Environment (development or production) |
| FileLocation | Location where the system log will be saved |
| FileTDRLocation | Location where the tdr log will be saved |
| FileMaxSize | Maximum size in Megabytes of a single log file. If the capacity reach, file will be saved but it will be renamed with suffix the current date |
| FileMaxBackup | Maximum number of backup file that will not be deleted |
| FileMaxAge | Number of days where the backup log will not be deleted |
| Stdout | Log will be printed in console if the value is true |
Initialize the loader by using
loggerConfig := golog.Config{
App: yourConfig.AppName,
AppVer: yourConfig.AppVersion,
Env: yourConfig.Environment,
FileLocation: yourConfig.Logger.FileLocation,
FileTDRLocation: yourConfig.Logger.FileTDRLocation,
FileMaxSize: yourConfig.FileMaxSize
FileMaxBackup: yourConfig.FileMaxBackup
FileMaxAge: yourConfig.FileMaxAge,
Stdout: yourConfig.Stdout,
}
golog.Loader(loggerConfig)Now you can use golog from anywhere in your project.
Example:
-
golog.Info(yourcontext, message)to print the log. -
golog.Error(yourcontext, message, err)to print error log.
other interface golog.Debug, golog.Warn, golog.Fatal, golog.Panic also available.
Make sure to add value to these keys traceId, srcIP, port, path in your context to make it easier to trace.
This library provide 2 kind of logs. System log and TDR log. Besides TDR function, it will print to system log.
In default, the file will be printed in file. You can decide whether the output will be printed in console or not. Just put true in Stdout config attribute to print the log in console.
Log file will be auto rotated based on file size. If the file size bigger than the config, will be saved to a new file with additional date in file name.
Contributions are welcome! Please follow the Contribution Guidelines.
This project is licensed under the MIT License.