Skip to content

Commit

Permalink
Issue cihub#95.
Browse files Browse the repository at this point in the history
  • Loading branch information
goodsign committed Sep 30, 2015
1 parent 785185d commit 5841159
Show file tree
Hide file tree
Showing 34 changed files with 390 additions and 345 deletions.
4 changes: 2 additions & 2 deletions behavior_adaptivelogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type asyncAdaptiveLogger struct {
maxInterval time.Duration
}

// newAsyncLoopLogger creates a new asynchronous adaptive logger
func newAsyncAdaptiveLogger(
// NewAsyncLoopLogger creates a new asynchronous adaptive logger
func NewAsyncAdaptiveLogger(
config *logConfig,
minInterval time.Duration,
maxInterval time.Duration,
Expand Down
4 changes: 2 additions & 2 deletions behavior_asynclooplogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type asyncLoopLogger struct {
asyncLogger
}

// newAsyncLoopLogger creates a new asynchronous loop logger
func newAsyncLoopLogger(config *logConfig) *asyncLoopLogger {
// NewAsyncLoopLogger creates a new asynchronous loop logger
func NewAsyncLoopLogger(config *logConfig) *asyncLoopLogger {

asnLoopLogger := new(asyncLoopLogger)

Expand Down
4 changes: 2 additions & 2 deletions behavior_asynctimerlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type asyncTimerLogger struct {
interval time.Duration
}

// newAsyncLoopLogger creates a new asynchronous loop logger
func newAsyncTimerLogger(config *logConfig, interval time.Duration) (*asyncTimerLogger, error) {
// NewAsyncLoopLogger creates a new asynchronous loop logger
func NewAsyncTimerLogger(config *logConfig, interval time.Duration) (*asyncTimerLogger, error) {

if interval <= 0 {
return nil, errors.New("async logger interval should be > 0")
Expand Down
4 changes: 2 additions & 2 deletions behavior_synclogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type syncLogger struct {
commonLogger
}

// newSyncLogger creates a new synchronous logger
func newSyncLogger(config *logConfig) *syncLogger {
// NewSyncLogger creates a new synchronous logger
func NewSyncLogger(config *logConfig) *syncLogger {
syncLogger := new(syncLogger)

syncLogger.commonLogger = *newCommonLogger(config, syncLogger)
Expand Down
42 changes: 21 additions & 21 deletions cfg_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func LoggerFromConfigAsFile(fileName string) (LoggerInterface, error) {
return nil, err
}

return createLoggerFromConfig(conf)
return createLoggerFromFullConfig(conf)
}

// LoggerFromConfigAsBytes creates a logger with config from bytes stream. Bytes should contain valid seelog xml.
Expand All @@ -54,7 +54,7 @@ func LoggerFromConfigAsBytes(data []byte) (LoggerInterface, error) {
return nil, err
}

return createLoggerFromConfig(conf)
return createLoggerFromFullConfig(conf)
}

// LoggerFromConfigAsString creates a logger with config from a string. String should contain valid seelog xml.
Expand All @@ -63,8 +63,8 @@ func LoggerFromConfigAsString(data string) (LoggerInterface, error) {
}

// LoggerFromParamConfigAsFile does the same as LoggerFromConfigAsFile, but includes special parser options.
// See 'CfgParseParams' comments.
func LoggerFromParamConfigAsFile(fileName string, parserParams *CfgParseParams) (LoggerInterface, error) {
// See 'cfgParseParams' comments.
func LoggerFromParamConfigAsFile(fileName string, parserParams *cfgParseParams) (LoggerInterface, error) {
file, err := os.Open(fileName)
if err != nil {
return nil, err
Expand All @@ -76,23 +76,23 @@ func LoggerFromParamConfigAsFile(fileName string, parserParams *CfgParseParams)
return nil, err
}

return createLoggerFromConfig(conf)
return createLoggerFromFullConfig(conf)
}

// LoggerFromParamConfigAsBytes does the same as LoggerFromConfigAsBytes, but includes special parser options.
// See 'CfgParseParams' comments.
func LoggerFromParamConfigAsBytes(data []byte, parserParams *CfgParseParams) (LoggerInterface, error) {
// See 'cfgParseParams' comments.
func LoggerFromParamConfigAsBytes(data []byte, parserParams *cfgParseParams) (LoggerInterface, error) {
conf, err := configFromReaderWithConfig(bytes.NewBuffer(data), parserParams)
if err != nil {
return nil, err
}

return createLoggerFromConfig(conf)
return createLoggerFromFullConfig(conf)
}

// LoggerFromParamConfigAsString does the same as LoggerFromConfigAsString, but includes special parser options.
// See 'CfgParseParams' comments.
func LoggerFromParamConfigAsString(data string, parserParams *CfgParseParams) (LoggerInterface, error) {
// See 'cfgParseParams' comments.
func LoggerFromParamConfigAsString(data string, parserParams *cfgParseParams) (LoggerInterface, error) {
return LoggerFromParamConfigAsBytes([]byte(data), parserParams)
}

Expand All @@ -109,25 +109,25 @@ func LoggerFromWriterWithMinLevel(output io.Writer, minLevel LogLevel) (LoggerIn
//
// Can be called for usage with non-Seelog systems
func LoggerFromWriterWithMinLevelAndFormat(output io.Writer, minLevel LogLevel, format string) (LoggerInterface, error) {
constraints, err := newMinMaxConstraints(minLevel, CriticalLvl)
constraints, err := NewMinMaxConstraints(minLevel, CriticalLvl)
if err != nil {
return nil, err
}
formatter, err := newFormatter(format)
formatter, err := NewFormatter(format)
if err != nil {
return nil, err
}
dispatcher, err := newSplitDispatcher(formatter, []interface{}{output})
dispatcher, err := NewSplitDispatcher(formatter, []interface{}{output})
if err != nil {
return nil, err
}

conf, err := newConfig(constraints, make([]*logLevelException, 0), dispatcher, syncloggerTypeFromString, nil, nil)
conf, err := newFullLoggerConfig(constraints, make([]*LogLevelException, 0), dispatcher, syncloggerTypeFromString, nil, nil)
if err != nil {
return nil, err
}

return createLoggerFromConfig(conf)
return createLoggerFromFullConfig(conf)
}

// LoggerFromXMLDecoder creates logger with config from a XML decoder starting from a specific node.
Expand All @@ -138,7 +138,7 @@ func LoggerFromXMLDecoder(xmlParser *xml.Decoder, rootNode xml.Token) (LoggerInt
return nil, err
}

return createLoggerFromConfig(conf)
return createLoggerFromFullConfig(conf)
}

// LoggerFromCustomReceiver creates a proxy logger that uses a CustomReceiver as the
Expand All @@ -165,24 +165,24 @@ func LoggerFromXMLDecoder(xmlParser *xml.Decoder, rootNode xml.Token) (LoggerInt
// * LoggerFromCustomReceiver takes value and uses it without modification and
// reinstantiation, directy passing it to the dispatcher tree.
func LoggerFromCustomReceiver(receiver CustomReceiver) (LoggerInterface, error) {
constraints, err := newMinMaxConstraints(TraceLvl, CriticalLvl)
constraints, err := NewMinMaxConstraints(TraceLvl, CriticalLvl)
if err != nil {
return nil, err
}

output, err := newCustomReceiverDispatcherByValue(msgonlyformatter, receiver, "user-proxy", CustomReceiverInitArgs{})
output, err := NewCustomReceiverDispatcherByValue(msgonlyformatter, receiver, "user-proxy", CustomReceiverInitArgs{})
if err != nil {
return nil, err
}
dispatcher, err := newSplitDispatcher(msgonlyformatter, []interface{}{output})
dispatcher, err := NewSplitDispatcher(msgonlyformatter, []interface{}{output})
if err != nil {
return nil, err
}

conf, err := newConfig(constraints, make([]*logLevelException, 0), dispatcher, syncloggerTypeFromString, nil, nil)
conf, err := newFullLoggerConfig(constraints, make([]*LogLevelException, 0), dispatcher, syncloggerTypeFromString, nil, nil)
if err != nil {
return nil, err
}

return createLoggerFromConfig(conf)
return createLoggerFromFullConfig(conf)
}
29 changes: 20 additions & 9 deletions cfg_logconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,42 @@ func getLoggerTypeFromString(logTypeString string) (level loggerTypeFromString,
}

// logConfig stores logging configuration. Contains messages dispatcher, allowed log level rules
// (general constraints and exceptions), and messages formats (used by nodes of dispatcher tree)
// (general constraints and exceptions)
type logConfig struct {
Constraints logLevelConstraints // General log level rules (>min and <max, or set of allowed levels)
Exceptions []*logLevelException // Exceptions to general rules for specific files or funcs
Exceptions []*LogLevelException // Exceptions to general rules for specific files or funcs
RootDispatcher dispatcherInterface // Root of output tree
LogType loggerTypeFromString
LoggerData interface{}
Params *CfgParseParams // Check cfg_parser: CfgParseParams
}

func newConfig(
func NewLoggerConfig(c logLevelConstraints, e []*LogLevelException, d dispatcherInterface) *logConfig {
return &logConfig{c, e, d}
}

// configForParsing is used when parsing config from file: logger type is deduced from string, params
// need to be converted from attributes to values and passed to specific logger constructor. Also,
// custom registered receivers and other parse params are used in this case.
type configForParsing struct {
logConfig
LogType loggerTypeFromString
LoggerData interface{}
Params *cfgParseParams // Check cfg_parser: cfgParseParams
}

func newFullLoggerConfig(
constraints logLevelConstraints,
exceptions []*logLevelException,
exceptions []*LogLevelException,
rootDispatcher dispatcherInterface,
logType loggerTypeFromString,
logData interface{},
cfgParams *CfgParseParams) (*logConfig, error) {
cfgParams *cfgParseParams) (*configForParsing, error) {
if constraints == nil {
return nil, errors.New("constraints can not be nil")
}
if rootDispatcher == nil {
return nil, errors.New("rootDispatcher can not be nil")
}

config := new(logConfig)
config := new(configForParsing)
config.Constraints = constraints
config.Exceptions = exceptions
config.RootDispatcher = rootDispatcher
Expand Down
Loading

0 comments on commit 5841159

Please sign in to comment.