Documentation ¶
Index ¶
- Constants
- func GenerateUUID() string
- func GetCurrentUserHomeDir() (string, error)
- func GetFilepathSeparator() string
- func IsFileExists(path string) bool
- func LockFile(file string) error
- func ReadFileContent(file string) ([]byte, error)
- func RenameFile(file string, targetFile string, permission os.FileMode) error
- func UnlockFile(file string) error
- func WriteStringToFile(file string, content string) error
- type ConsoleLogger
- type FlexLogger
- func (f *FlexLogger) AddLogger(logger ILogger) *FlexLogger
- func (f *FlexLogger) Debug(p []byte) (int, error)
- func (f *FlexLogger) DebugWithOptions(p []byte, options map[string]bool) (int, error)
- func (f *FlexLogger) Err(p []byte) (int, error)
- func (f *FlexLogger) ErrWithOptions(p []byte, options map[string]bool) (int, error)
- func (f *FlexLogger) GetLoggerNames() []string
- func (f *FlexLogger) Info(p []byte) (int, error)
- func (f *FlexLogger) InfoWithOptions(p []byte, options map[string]bool) (int, error)
- func (f *FlexLogger) Release(optionalParam map[string]interface{}) error
- func (f *FlexLogger) Warn(p []byte) (int, error)
- func (f *FlexLogger) WarnWithOptions(p []byte, options map[string]bool) (int, error)
- func (f *FlexLogger) Write(p []byte) (n int, err error)
- func (f *FlexLogger) WriteWithOptions(p []byte, options map[string]bool, logLevel int) (n int, err error)
- type ILogger
- type IReleasable
- type RollingFileLogger
Constants ¶
const LogLevelDebug = 1
const LogLevelErr = 8
const LogLevelInfo = 2
const LogLevelWarn = 4
Variables ¶
This section is empty.
Functions ¶
func GenerateUUID ¶
func GenerateUUID() string
return a generated UUID based on betterguid library (timestamp + 72 bits of random characters)
func GetCurrentUserHomeDir ¶
return the current user's home directory (string)
func GetFilepathSeparator ¶
func GetFilepathSeparator() string
method to return the correct filepath separator based on the OS
func ReadFileContent ¶
read the given file; assume the file exist check has passed before calling this method
func RenameFile ¶
rename the given file to the target destination. Assume the source passed the exists check
func WriteStringToFile ¶
write the given "content" to the "file" path
Types ¶
type ConsoleLogger ¶
type ConsoleLogger struct { }
Logger for console / stdout logging
func (*ConsoleLogger) Name ¶
func (l *ConsoleLogger) Name() string
func (*ConsoleLogger) Release ¶
func (l *ConsoleLogger) Release(optionalParam map[string]interface{}) error
type FlexLogger ¶
type FlexLogger struct { // map of ILogger instances for logging. Key is the name of the logger, // value is the ILogger implementation Loggers map[string]ILogger // the log level for the logger(s) LogLevel int }
func NewFlexLogger ¶
func NewFlexLogger() *FlexLogger
func (*FlexLogger) AddLogger ¶
func (f *FlexLogger) AddLogger(logger ILogger) *FlexLogger
method add the given logger implementation
func (*FlexLogger) DebugWithOptions ¶ added in v0.1.2
func (*FlexLogger) ErrWithOptions ¶ added in v0.1.2
func (*FlexLogger) GetLoggerNames ¶ added in v0.1.2
func (f *FlexLogger) GetLoggerNames() []string
return the configured ILogger(s)'s name
func (*FlexLogger) InfoWithOptions ¶ added in v0.1.2
func (*FlexLogger) Release ¶
func (f *FlexLogger) Release(optionalParam map[string]interface{}) error
release resources before the instance is removed
func (*FlexLogger) WarnWithOptions ¶ added in v0.1.2
func (*FlexLogger) Write ¶
func (f *FlexLogger) Write(p []byte) (n int, err error)
similar to calling WriteWithOptions([]byte, nil); which means all available Logger(s) would log the given message; plus using the default logLevel (which is info if not set)
func (*FlexLogger) WriteWithOptions ¶
func (f *FlexLogger) WriteWithOptions(p []byte, options map[string]bool, logLevel int) (n int, err error)
log message based on the options provided; if options is nil then all logger(s) will log the given []byte, else would need to check if a "true" is associated with logger's name in which a "true" indicates the logger to log the message;
type ILogger ¶
type ILogger interface { // implements the io.Writer interface; simply to be able to // "write" out []byte to the target stream Write(p []byte) (n int, err error) // return the name of the logger implementation Name() string // releasable implementation, so that resources could be released // when necessary Release(optionalParam map[string]interface{}) error }
acts as a common interface for logging implementations
type IReleasable ¶
type IReleasable interface { // operations to be done before closing the associated object. // This method is good for releasing expensive resources // to prevent memory leak Release(optionalParam map[string]interface{}) error }
acts as a common interface for "releasable" object(s)
type RollingFileLogger ¶
type RollingFileLogger struct {
// contains filtered or unexported fields
}
func NewRollingFileLogger ¶
func NewRollingFileLogger(filename string, maxFileSize, maxBackup, maxRetentionDays int, compress bool) *RollingFileLogger
method to create a lumberjackLogger instance. LumberjackLogger is an implementation for rolling file logger
func (*RollingFileLogger) Name ¶
func (l *RollingFileLogger) Name() string
func (*RollingFileLogger) Release ¶
func (l *RollingFileLogger) Release(optionalParam map[string]interface{}) error