queutil

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 11 Imported by: 1

README

queutil

utilities for que broker messaging system

Documentation

Index

Constants

View Source
const LogLevelDebug = 1
View Source
const LogLevelErr = 8
View Source
const LogLevelInfo = 2
View Source
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

func GetCurrentUserHomeDir() (string, error)

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 IsFileExists

func IsFileExists(path string) bool

check if the given file exists or not

func LockFile

func LockFile(file string) error

method to lock a file (exclusive lock and non-blocking)

func ReadFileContent

func ReadFileContent(file string) ([]byte, error)

read the given file; assume the file exist check has passed before calling this method

func RenameFile

func RenameFile(file string, targetFile string, permission os.FileMode) error

rename the given file to the target destination. Assume the source passed the exists check

func UnlockFile

func UnlockFile(file string) error

method to unlock the given file

func WriteStringToFile

func WriteStringToFile(file string, content string) error

write the given "content" to the "file" path

Types

type ConsoleLogger

type ConsoleLogger struct {
}

Logger for console / stdout logging

func NewConsoleLogger

func NewConsoleLogger() *ConsoleLogger

method to create a console logger

func (*ConsoleLogger) Name

func (l *ConsoleLogger) Name() string

func (*ConsoleLogger) Release

func (l *ConsoleLogger) Release(optionalParam map[string]interface{}) error

func (*ConsoleLogger) Write

func (l *ConsoleLogger) Write(p []byte) (n int, err error)

simple just write to the stdout

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) Debug added in v0.1.2

func (f *FlexLogger) Debug(p []byte) (int, error)

func (*FlexLogger) DebugWithOptions added in v0.1.2

func (f *FlexLogger) DebugWithOptions(p []byte, options map[string]bool) (int, error)

func (*FlexLogger) Err added in v0.1.2

func (f *FlexLogger) Err(p []byte) (int, error)

func (*FlexLogger) ErrWithOptions added in v0.1.2

func (f *FlexLogger) ErrWithOptions(p []byte, options map[string]bool) (int, error)

func (*FlexLogger) GetLoggerNames added in v0.1.2

func (f *FlexLogger) GetLoggerNames() []string

return the configured ILogger(s)'s name

func (*FlexLogger) Info added in v0.1.2

func (f *FlexLogger) Info(p []byte) (int, error)

func (*FlexLogger) InfoWithOptions added in v0.1.2

func (f *FlexLogger) InfoWithOptions(p []byte, options map[string]bool) (int, error)

func (*FlexLogger) Release

func (f *FlexLogger) Release(optionalParam map[string]interface{}) error

release resources before the instance is removed

func (*FlexLogger) Warn added in v0.1.2

func (f *FlexLogger) Warn(p []byte) (int, error)

func (*FlexLogger) WarnWithOptions added in v0.1.2

func (f *FlexLogger) WarnWithOptions(p []byte, options map[string]bool) (int, error)

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

func (*RollingFileLogger) Write

func (l *RollingFileLogger) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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