diff --git a/behavior_adaptivelogger.go b/behavior_adaptivelogger.go index 11f10c2..0c640ca 100644 --- a/behavior_adaptivelogger.go +++ b/behavior_adaptivelogger.go @@ -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, diff --git a/behavior_asynclooplogger.go b/behavior_asynclooplogger.go index fdb3542..972467b 100644 --- a/behavior_asynclooplogger.go +++ b/behavior_asynclooplogger.go @@ -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) diff --git a/behavior_asynctimerlogger.go b/behavior_asynctimerlogger.go index 581e984..8118f20 100644 --- a/behavior_asynctimerlogger.go +++ b/behavior_asynctimerlogger.go @@ -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") diff --git a/behavior_synclogger.go b/behavior_synclogger.go index 1a6932a..5a022eb 100644 --- a/behavior_synclogger.go +++ b/behavior_synclogger.go @@ -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) diff --git a/cfg_config.go b/cfg_config.go index e06dc27..5da03dd 100644 --- a/cfg_config.go +++ b/cfg_config.go @@ -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. @@ -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. @@ -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 @@ -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) } @@ -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. @@ -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 @@ -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) } diff --git a/cfg_logconfig.go b/cfg_logconfig.go index 0898c51..119cb38 100644 --- a/cfg_logconfig.go +++ b/cfg_logconfig.go @@ -76,23 +76,34 @@ 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 ' element. It takes the 'name' attribute // of the element and tries to find a match in two places: - // 1) CfgParseParams.CustomReceiverProducers map + // 1) cfgParseParams.CustomReceiverProducers map // 2) Global type map, filled by RegisterReceiver // // If a match is found in the CustomReceiverProducers map, parser calls the corresponding producer func @@ -130,12 +130,12 @@ type CfgParseParams struct { CustomReceiverProducers map[string]CustomReceiverProducer } -func (cfg *CfgParseParams) String() string { +func (cfg *cfgParseParams) String() string { return fmt.Sprintf("CfgParams: {custom_recs=%d}", len(cfg.CustomReceiverProducers)) } type elementMapEntry struct { - constructor func(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) + constructor func(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) } var elementMap map[string]elementMapEntry @@ -180,7 +180,7 @@ func fillPredefinedFormats() error { predefinedFormats = make(map[string]*formatter) for formatKey, format := range predefinedFormatsWithoutPrefix { - formatter, err := newFormatter(format) + formatter, err := NewFormatter(format) if err != nil { return err } @@ -194,14 +194,14 @@ func fillPredefinedFormats() error { // configFromXMLDecoder parses data from a given XML decoder. // Returns parsed config which can be used to create logger in case no errors occured. // Returns error if format is incorrect or anything happened. -func configFromXMLDecoder(xmlParser *xml.Decoder, rootNode xml.Token) (*logConfig, error) { +func configFromXMLDecoder(xmlParser *xml.Decoder, rootNode xml.Token) (*configForParsing, error) { return configFromXMLDecoderWithConfig(xmlParser, rootNode, nil) } // configFromXMLDecoderWithConfig parses data from a given XML decoder. // Returns parsed config which can be used to create logger in case no errors occured. // Returns error if format is incorrect or anything happened. -func configFromXMLDecoderWithConfig(xmlParser *xml.Decoder, rootNode xml.Token, cfg *CfgParseParams) (*logConfig, error) { +func configFromXMLDecoderWithConfig(xmlParser *xml.Decoder, rootNode xml.Token, cfg *cfgParseParams) (*configForParsing, error) { _, ok := rootNode.(xml.StartElement) if !ok { return nil, errors.New("rootNode must be XML startElement") @@ -221,14 +221,14 @@ func configFromXMLDecoderWithConfig(xmlParser *xml.Decoder, rootNode xml.Token, // configFromReader parses data from a given reader. // Returns parsed config which can be used to create logger in case no errors occured. // Returns error if format is incorrect or anything happened. -func configFromReader(reader io.Reader) (*logConfig, error) { +func configFromReader(reader io.Reader) (*configForParsing, error) { return configFromReaderWithConfig(reader, nil) } // configFromReaderWithConfig parses data from a given reader. // Returns parsed config which can be used to create logger in case no errors occured. // Returns error if format is incorrect or anything happened. -func configFromReaderWithConfig(reader io.Reader, cfg *CfgParseParams) (*logConfig, error) { +func configFromReaderWithConfig(reader io.Reader, cfg *cfgParseParams) (*configForParsing, error) { config, err := unmarshalConfig(reader) if err != nil { return nil, err @@ -241,7 +241,7 @@ func configFromReaderWithConfig(reader io.Reader, cfg *CfgParseParams) (*logConf return configFromXMLNodeWithConfig(config, cfg) } -func configFromXMLNodeWithConfig(config *xmlNode, cfg *CfgParseParams) (*logConfig, error) { +func configFromXMLNodeWithConfig(config *xmlNode, cfg *cfgParseParams) (*configForParsing, error) { err := checkUnexpectedAttribute( config, minLevelID, @@ -297,7 +297,7 @@ func configFromXMLNodeWithConfig(config *xmlNode, cfg *CfgParseParams) (*logConf return nil, err } - return newConfig(constraints, exceptions, dispatcher, loggerType, logData, cfg) + return newFullLoggerConfig(constraints, exceptions, dispatcher, loggerType, logData, cfg) } func getConstraints(node *xmlNode) (logLevelConstraints, error) { @@ -315,7 +315,7 @@ func getConstraints(node *xmlNode) (logLevelConstraints, error) { if (isLevels && strings.TrimSpace(levelsStr) == offString) || (isMinLevel && !isMaxLevel && minLevelStr == offString) { - return newOffConstraints() + return NewOffConstraints() } if isLevels { @@ -323,7 +323,7 @@ func getConstraints(node *xmlNode) (logLevelConstraints, error) { if err != nil { return nil, err } - return newListConstraints(levels) + return NewListConstraints(levels) } var minLevel = LogLevel(TraceLvl) @@ -344,7 +344,7 @@ func getConstraints(node *xmlNode) (logLevelConstraints, error) { } } - return newMinMaxConstraints(minLevel, maxLevel) + return NewMinMaxConstraints(minLevel, maxLevel) } func parseLevels(str string) ([]LogLevel, error) { @@ -362,8 +362,8 @@ func parseLevels(str string) ([]LogLevel, error) { return levels, nil } -func getExceptions(config *xmlNode) ([]*logLevelException, error) { - var exceptions []*logLevelException +func getExceptions(config *xmlNode) ([]*LogLevelException, error) { + var exceptions []*LogLevelException var exceptionsNode *xmlNode for _, child := range config.children { @@ -411,7 +411,7 @@ func getExceptions(config *xmlNode) ([]*logLevelException, error) { filePattern = "*" } - exception, err := newLogLevelException(funcPattern, filePattern, constraints) + exception, err := NewLogLevelException(funcPattern, filePattern, constraints) if err != nil { return nil, errors.New("incorrect exception node: " + err.Error()) } @@ -422,7 +422,7 @@ func getExceptions(config *xmlNode) ([]*logLevelException, error) { return exceptions, nil } -func checkDistinctExceptions(exceptions []*logLevelException) error { +func checkDistinctExceptions(exceptions []*LogLevelException) error { for i, exception := range exceptions { for j, exception1 := range exceptions { if i == j { @@ -485,7 +485,7 @@ func getFormats(config *xmlNode) (map[string]*formatter, error) { return nil, errors.New("format[" + id + "] has no '" + formatAttrID + "' attribute") } - formatter, err := newFormatter(formatStr) + formatter, err := NewFormatter(formatStr) if err != nil { return nil, err } @@ -559,7 +559,7 @@ func getloggerTypeFromStringData(config *xmlNode) (logType loggerTypeFromString, return logType, logData, nil } -func getOutputsTree(config *xmlNode, formats map[string]*formatter, cfg *CfgParseParams) (dispatcherInterface, error) { +func getOutputsTree(config *xmlNode, formats map[string]*formatter, cfg *cfgParseParams) (dispatcherInterface, error) { var outputsNode *xmlNode for _, child := range config.children { if child.name == outputsID { @@ -574,7 +574,7 @@ func getOutputsTree(config *xmlNode, formats map[string]*formatter, cfg *CfgPars return nil, err } - formatter, err := getCurrentFormat(outputsNode, defaultformatter, formats) + formatter, err := getCurrentFormat(outputsNode, DefaultFormatter, formats) if err != nil { return nil, err } @@ -590,11 +590,11 @@ func getOutputsTree(config *xmlNode, formats map[string]*formatter, cfg *CfgPars } } - console, err := newConsoleWriter() + console, err := NewConsoleWriter() if err != nil { return nil, err } - return newSplitDispatcher(defaultformatter, []interface{}{console}) + return NewSplitDispatcher(DefaultFormatter, []interface{}{console}) } func getCurrentFormat(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter) (*formatter, error) { @@ -618,7 +618,7 @@ func getCurrentFormat(node *xmlNode, formatFromParent *formatter, formats map[st return pdFormat, nil } -func createInnerReceivers(node *xmlNode, format *formatter, formats map[string]*formatter, cfg *CfgParseParams) ([]interface{}, error) { +func createInnerReceivers(node *xmlNode, format *formatter, formats map[string]*formatter, cfg *cfgParseParams) ([]interface{}, error) { var outputs []interface{} for _, childNode := range node.children { entry, ok := elementMap[childNode.name] @@ -637,7 +637,7 @@ func createInnerReceivers(node *xmlNode, format *formatter, formats map[string]* return outputs, nil } -func createSplitter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createSplitter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { err := checkUnexpectedAttribute(node, outputFormatID) if err != nil { return nil, err @@ -657,10 +657,10 @@ func createSplitter(node *xmlNode, formatFromParent *formatter, formats map[stri return nil, err } - return newSplitDispatcher(currentFormat, receivers) + return NewSplitDispatcher(currentFormat, receivers) } -func createCustomReceiver(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createCustomReceiver(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { dataCustomPrefixes := make(map[string]string) // Expecting only 'formatid', 'name' and 'data-' attrs for attr, attrval := range node.attributes { @@ -699,7 +699,7 @@ func createCustomReceiver(node *xmlNode, formatFromParent *formatter, formats ma if err != nil { return nil, err } - creceiver, err := newCustomReceiverDispatcherByValue(currentFormat, rec, customName, args) + creceiver, err := NewCustomReceiverDispatcherByValue(currentFormat, rec, customName, args) if err != nil { return nil, err } @@ -711,10 +711,10 @@ func createCustomReceiver(node *xmlNode, formatFromParent *formatter, formats ma } } - return newCustomReceiverDispatcher(currentFormat, customName, args) + return NewCustomReceiverDispatcher(currentFormat, customName, args) } -func createFilter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createFilter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { err := checkUnexpectedAttribute(node, outputFormatID, filterLevelsAttrID) if err != nil { return nil, err @@ -744,10 +744,10 @@ func createFilter(node *xmlNode, formatFromParent *formatter, formats map[string return nil, err } - return newFilterDispatcher(currentFormat, receivers, levels...) + return NewFilterDispatcher(currentFormat, receivers, levels...) } -func createfileWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createfileWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { err := checkUnexpectedAttribute(node, outputFormatID, pathID) if err != nil { return nil, err @@ -767,16 +767,16 @@ func createfileWriter(node *xmlNode, formatFromParent *formatter, formats map[st return nil, newMissingArgumentError(node.name, pathID) } - fileWriter, err := newFileWriter(path) + fileWriter, err := NewFileWriter(path) if err != nil { return nil, err } - return newFormattedWriter(fileWriter, currentFormat) + return NewFormattedWriter(fileWriter, currentFormat) } // Creates new SMTP writer if encountered in the config file. -func createSMTPWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createSMTPWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { err := checkUnexpectedAttribute(node, outputFormatID, senderaddressID, senderNameID, hostNameID, hostPortID, userNameID, userPassID, subjectID) if err != nil { return nil, err @@ -870,7 +870,7 @@ func createSMTPWriter(node *xmlNode, formatFromParent *formatter, formats map[st subjectPhrase = subject } - smtpWriter := newSMTPWriter( + smtpWriter := NewSMTPWriter( senderAddress, senderName, recipientAddresses, @@ -883,10 +883,10 @@ func createSMTPWriter(node *xmlNode, formatFromParent *formatter, formats map[st mailHeaders, ) - return newFormattedWriter(smtpWriter, currentFormat) + return NewFormattedWriter(smtpWriter, currentFormat) } -func createConsoleWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createConsoleWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { err := checkUnexpectedAttribute(node, outputFormatID) if err != nil { return nil, err @@ -901,15 +901,15 @@ func createConsoleWriter(node *xmlNode, formatFromParent *formatter, formats map return nil, err } - consoleWriter, err := newConsoleWriter() + consoleWriter, err := NewConsoleWriter() if err != nil { return nil, err } - return newFormattedWriter(consoleWriter, currentFormat) + return NewFormattedWriter(consoleWriter, currentFormat) } -func createconnWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createconnWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { if node.hasChildren() { return nil, errNodeCannotHaveChildren } @@ -970,16 +970,16 @@ func createconnWriter(node *xmlNode, formatFromParent *formatter, formats map[st } config := tls.Config{InsecureSkipVerify: insecureSkipVerify} connWriter := newTLSWriter(net, addr, reconnectOnMsg, &config) - return newFormattedWriter(connWriter, currentFormat) + return NewFormattedWriter(connWriter, currentFormat) } } - connWriter := newConnWriter(net, addr, reconnectOnMsg) + connWriter := NewConnWriter(net, addr, reconnectOnMsg) - return newFormattedWriter(connWriter, currentFormat) + return NewFormattedWriter(connWriter, currentFormat) } -func createRollingFileWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createRollingFileWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { if node.hasChildren() { return nil, errNodeCannotHaveChildren } @@ -1069,12 +1069,12 @@ func createRollingFileWriter(node *xmlNode, formatFromParent *formatter, formats } } - rollingWriter, err := newRollingFileWriterSize(path, rArchiveType, rArchivePath, maxSize, maxRolls, nameMode) + rollingWriter, err := NewRollingFileWriterSize(path, rArchiveType, rArchivePath, maxSize, maxRolls, nameMode) if err != nil { return nil, err } - return newFormattedWriter(rollingWriter, currentFormat) + return NewFormattedWriter(rollingWriter, currentFormat) } else if rollingType == rollingTypeTime { err := checkUnexpectedAttribute(node, outputFormatID, rollingFileTypeAttr, rollingFilePathAttr, @@ -1098,18 +1098,18 @@ func createRollingFileWriter(node *xmlNode, formatFromParent *formatter, formats return nil, newMissingArgumentError(node.name, rollingFileDataPatternAttr) } - rollingWriter, err := newRollingFileWriterTime(path, rArchiveType, rArchivePath, maxRolls, dataPattern, rollingIntervalAny, nameMode) + rollingWriter, err := NewRollingFileWriterTime(path, rArchiveType, rArchivePath, maxRolls, dataPattern, rollingIntervalAny, nameMode) if err != nil { return nil, err } - return newFormattedWriter(rollingWriter, currentFormat) + return NewFormattedWriter(rollingWriter, currentFormat) } return nil, errors.New("incorrect rolling writer type " + rollingTypeStr) } -func createbufferedWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *CfgParseParams) (interface{}, error) { +func createbufferedWriter(node *xmlNode, formatFromParent *formatter, formats map[string]*formatter, cfg *cfgParseParams) (interface{}, error) { err := checkUnexpectedAttribute(node, outputFormatID, bufferedSizeAttr, bufferedFlushPeriodAttr) if err != nil { return nil, err @@ -1159,12 +1159,12 @@ func createbufferedWriter(node *xmlNode, formatFromParent *formatter, formats ma return nil, errors.New("inner writer cannot have his own format") } - bufferedWriter, err := newBufferedWriter(formattedWriter.Writer(), size, time.Duration(flushPeriod)) + bufferedWriter, err := NewBufferedWriter(formattedWriter.Writer(), size, time.Duration(flushPeriod)) if err != nil { return nil, err } - return newFormattedWriter(bufferedWriter, currentFormat) + return NewFormattedWriter(bufferedWriter, currentFormat) } // Returns an error if node has any attributes not listed in expectedAttrs. diff --git a/cfg_parser_test.go b/cfg_parser_test.go index 107d532..ca6795f 100644 --- a/cfg_parser_test.go +++ b/cfg_parser_test.go @@ -82,9 +82,9 @@ var parserTests []parserTest type parserTest struct { testName string config string - expected *logConfig //interface{} + expected *configForParsing //interface{} errorExpected bool - parserConfig *CfgParseParams + parserConfig *cfgParseParams } func getParserTests() []parserTest { @@ -100,11 +100,11 @@ func getParserTests() []parserTest { ` - testExpected := new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected := new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testfileWriter, _ := newFileWriter(testLogFileName) - testHeadSplitter, _ := newSplitDispatcher(defaultformatter, []interface{}{testfileWriter}) + testfileWriter, _ := NewFileWriter(testLogFileName) + testHeadSplitter, _ := NewSplitDispatcher(DefaultFormatter, []interface{}{testfileWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -120,12 +120,12 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testfileWriter, _ = newFileWriter(testLogFileName) - testFilter, _ := newFilterDispatcher(defaultformatter, []interface{}{testfileWriter}, DebugLvl, InfoLvl, CriticalLvl) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testFilter}) + testfileWriter, _ = NewFileWriter(testLogFileName) + testFilter, _ := NewFilterDispatcher(DefaultFormatter, []interface{}{testfileWriter}, DebugLvl, InfoLvl, CriticalLvl) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testFilter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -138,11 +138,11 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testconsoleWriter, _ := newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ := NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -162,10 +162,10 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testSMTPWriter := newSMTPWriter( + testSMTPWriter := NewSMTPWriter( "sa", "sn", []string{"ra1", "ra2", "ra3"}, @@ -177,7 +177,7 @@ func getParserTests() []parserTest { DefaultSubjectPhrase, nil, ) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testSMTPWriter}) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testSMTPWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -197,10 +197,10 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testSMTPWriter = newSMTPWriter( + testSMTPWriter = NewSMTPWriter( "sa", "sn", []string{"ra1"}, @@ -212,7 +212,7 @@ func getParserTests() []parserTest { "ohlala", []string{"Priority: Urgent", "Importance: high", "Sensitivity: Company-Confidential", "Auto-Submitted: auto-generated"}, ) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testSMTPWriter}) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testSMTPWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -221,11 +221,11 @@ func getParserTests() []parserTest { testConfig = ` ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -234,11 +234,11 @@ func getParserTests() []parserTest { testConfig = ` ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -247,11 +247,11 @@ func getParserTests() []parserTest { testConfig = ` ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = asyncTimerloggerTypeFromString testExpected.LoggerData = asyncTimerLoggerData{101} testExpected.RootDispatcher = testHeadSplitter @@ -266,11 +266,11 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriter, _ := newRollingFileWriterSize(testLogFileName, rollingArchiveNone, "", 100, 5, rollingNameModePostfix) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testrollingFileWriter}) + testrollingFileWriter, _ := NewRollingFileWriterSize(testLogFileName, rollingArchiveNone, "", 100, 5, rollingNameModePostfix) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testrollingFileWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -283,11 +283,11 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriter, _ = newRollingFileWriterSize(testLogFileName, rollingArchiveZip, "log.zip", 100, 5, rollingNameModePostfix) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testrollingFileWriter}) + testrollingFileWriter, _ = NewRollingFileWriterSize(testLogFileName, rollingArchiveZip, "log.zip", 100, 5, rollingNameModePostfix) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testrollingFileWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -300,11 +300,11 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriter, _ = newRollingFileWriterSize(testLogFileName, rollingArchiveZip, "test.zip", 100, 5, rollingNameModePrefix) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testrollingFileWriter}) + testrollingFileWriter, _ = NewRollingFileWriterSize(testLogFileName, rollingArchiveZip, "test.zip", 100, 5, rollingNameModePrefix) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testrollingFileWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -317,11 +317,11 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriter, _ = newRollingFileWriterSize(testLogFileName, rollingArchiveNone, "", 100, 5, rollingNameModePostfix) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testrollingFileWriter}) + testrollingFileWriter, _ = NewRollingFileWriterSize(testLogFileName, rollingArchiveNone, "", 100, 5, rollingNameModePostfix) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testrollingFileWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -334,11 +334,11 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriterTime, _ := newRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalAny, rollingNameModePostfix) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testrollingFileWriterTime}) + testrollingFileWriterTime, _ := NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalAny, rollingNameModePostfix) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testrollingFileWriterTime}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -353,12 +353,12 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriterTime, _ = newRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalDaily, rollingNameModePostfix) - testbufferedWriter, _ := newBufferedWriter(testrollingFileWriterTime, 100500, 100) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testbufferedWriter}) + testrollingFileWriterTime, _ = NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalDaily, rollingNameModePostfix) + testbufferedWriter, _ := NewBufferedWriter(testrollingFileWriterTime, 100500, 100) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testbufferedWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -378,14 +378,14 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testfileWriter1, _ := newFileWriter(testLogFileName2) - testfileWriter2, _ := newFileWriter(testLogFileName3) - testInnerSplitter, _ := newSplitDispatcher(defaultformatter, []interface{}{testfileWriter1, testfileWriter2}) - testfileWriter, _ = newFileWriter(testLogFileName1) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testfileWriter, testInnerSplitter}) + testfileWriter1, _ := NewFileWriter(testLogFileName2) + testfileWriter2, _ := NewFileWriter(testLogFileName3) + testInnerSplitter, _ := NewSplitDispatcher(DefaultFormatter, []interface{}{testfileWriter1, testfileWriter2}) + testfileWriter, _ = NewFileWriter(testLogFileName1) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testfileWriter, testInnerSplitter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -400,15 +400,15 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testCustomReceiver, _ := newCustomReceiverDispatcher(defaultformatter, "custom-name-1", CustomReceiverInitArgs{ + testCustomReceiver, _ := NewCustomReceiverDispatcher(DefaultFormatter, "custom-name-1", CustomReceiverInitArgs{ XmlCustomAttrs: map[string]string{ "test": "set", }, }) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testCustomReceiver}) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testCustomReceiver}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -421,8 +421,8 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil crec := &customTestReceiver{} cargs := CustomReceiverInitArgs{ @@ -431,14 +431,14 @@ func getParserTests() []parserTest { }, } crec.AfterParse(cargs) - testCustomReceiver2, _ := newCustomReceiverDispatcherByValue(defaultformatter, crec, "custom-name-2", cargs) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testCustomReceiver2}) + testCustomReceiver2, _ := NewCustomReceiverDispatcherByValue(DefaultFormatter, crec, "custom-name-2", cargs) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testCustomReceiver2}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter fnc := func(initArgs CustomReceiverInitArgs) (CustomReceiver, error) { return &customTestReceiver{}, nil } - cfg := CfgParseParams{ + cfg := cfgParseParams{ CustomReceiverProducers: map[string]CustomReceiverProducer{ "custom-name-2": CustomReceiverProducer(fnc), }, @@ -455,8 +455,8 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil creccustom := &customTestReceiver{} cargs3 := CustomReceiverInitArgs{ @@ -465,8 +465,8 @@ func getParserTests() []parserTest { }, } creccustom.AfterParse(cargs3) - testCustomReceiver, _ = newCustomReceiverDispatcherByValue(defaultformatter, creccustom, "-", cargs3) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testCustomReceiver}) + testCustomReceiver, _ = NewCustomReceiverDispatcherByValue(DefaultFormatter, creccustom, "-", cargs3) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testCustomReceiver}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -481,19 +481,19 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil testCustomReceivers := make([]*customReceiverDispatcher, 3) for i := 0; i < 3; i++ { - testCustomReceivers[i], _ = newCustomReceiverDispatcher(defaultformatter, "custom-name-1", CustomReceiverInitArgs{ + testCustomReceivers[i], _ = NewCustomReceiverDispatcher(DefaultFormatter, "custom-name-1", CustomReceiverInitArgs{ XmlCustomAttrs: map[string]string{ "test": fmt.Sprintf("set%d", i+1), }, }) } - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testCustomReceivers[0], testCustomReceivers[1], testCustomReceivers[2]}) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testCustomReceivers[0], testCustomReceivers[1], testCustomReceivers[2]}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -510,12 +510,12 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testfileWriter, _ = newFileWriter(testLogFileName) - testFormat, _ := newFormatter("%Level %Msg %File") - testHeadSplitter, _ = newSplitDispatcher(testFormat, []interface{}{testfileWriter}) + testfileWriter, _ = NewFileWriter(testLogFileName) + testFormat, _ := NewFormatter("%Level %Msg %File") + testHeadSplitter, _ = NewSplitDispatcher(testFormat, []interface{}{testfileWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -535,59 +535,59 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testfileWriter, _ = newFileWriter(testLogFileName) - testfileWriter1, _ = newFileWriter(testLogFileName1) - testFormat1, _ := newFormatter("%Level %Msg %File") - testFormat2, _ := newFormatter("%l %Msg") - formattedWriter, _ := newFormattedWriter(testfileWriter1, testFormat2) - testHeadSplitter, _ = newSplitDispatcher(testFormat1, []interface{}{testfileWriter, formattedWriter}) + testfileWriter, _ = NewFileWriter(testLogFileName) + testfileWriter1, _ = NewFileWriter(testLogFileName1) + testFormat1, _ := NewFormatter("%Level %Msg %File") + testFormat2, _ := NewFormatter("%l %Msg") + formattedWriter, _ := NewFormattedWriter(testfileWriter1, testFormat2) + testHeadSplitter, _ = NewSplitDispatcher(testFormat1, []interface{}{testfileWriter, formattedWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) testName = "Minlevel = warn" testConfig = `` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(WarnLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(WarnLvl, CriticalLvl) testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) testName = "Maxlevel = trace" testConfig = `` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, TraceLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, TraceLvl) testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) testName = "Level between info and error" testConfig = `` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(InfoLvl, ErrorLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(InfoLvl, ErrorLvl) testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) testName = "Off with minlevel" testConfig = `` - testExpected = new(logConfig) - testExpected.Constraints, _ = newOffConstraints() + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewOffConstraints() testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -598,12 +598,12 @@ func getParserTests() []parserTest { testName = "Levels list" testConfig = `` - testExpected = new(logConfig) - testExpected.Constraints, _ = newListConstraints([]LogLevel{ + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewListConstraints([]LogLevel{ DebugLvl, InfoLvl, CriticalLvl}) testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = asyncLooploggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -694,13 +694,13 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) - listConstraint, _ := newOffConstraints() - exception, _ := newLogLevelException("Test*", "someFile.go", listConstraint) - testExpected.Exceptions = []*logLevelException{exception} - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) + listConstraint, _ := NewOffConstraints() + exception, _ := NewLogLevelException("Test*", "someFile.go", listConstraint) + testExpected.Exceptions = []*LogLevelException{exception} + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -714,13 +714,13 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newListConstraints([]LogLevel{ErrorLvl}) - minMaxConstraint, _ := newMinMaxConstraints(TraceLvl, CriticalLvl) - exception, _ = newLogLevelException("*", "testfile.go", minMaxConstraint) - testExpected.Exceptions = []*logLevelException{exception} - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewListConstraints([]LogLevel{ErrorLvl}) + minMaxConstraint, _ := NewMinMaxConstraints(TraceLvl, CriticalLvl) + exception, _ = NewLogLevelException("*", "testfile.go", minMaxConstraint) + testExpected.Exceptions = []*LogLevelException{exception} + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -733,13 +733,13 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newOffConstraints() - minMaxConstraint, _ = newMinMaxConstraints(WarnLvl, CriticalLvl) - exception, _ = newLogLevelException("*", "testfile.go", minMaxConstraint) - testExpected.Exceptions = []*logLevelException{exception} - testconsoleWriter, _ = newConsoleWriter() - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testconsoleWriter}) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewOffConstraints() + minMaxConstraint, _ = NewMinMaxConstraints(WarnLvl, CriticalLvl) + exception, _ = NewLogLevelException("*", "testfile.go", minMaxConstraint) + testExpected.Exceptions = []*LogLevelException{exception} + testconsoleWriter, _ = NewConsoleWriter() + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testconsoleWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -752,12 +752,12 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testconsoleWriter, _ = newConsoleWriter() + testconsoleWriter, _ = NewConsoleWriter() testFormat, _ = predefinedFormats[formatID] - testHeadSplitter, _ = newSplitDispatcher(testFormat, []interface{}{testconsoleWriter}) + testHeadSplitter, _ = NewSplitDispatcher(testFormat, []interface{}{testconsoleWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -774,12 +774,12 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testfileWriter, _ = newFileWriter(testLogFileName) - testFormat, _ = newFormatter("%Level %Msg %File") - testHeadSplitter, _ = newSplitDispatcher(testFormat, []interface{}{testfileWriter}) + testfileWriter, _ = NewFileWriter(testLogFileName) + testFormat, _ = NewFormatter("%Level %Msg %File") + testHeadSplitter, _ = NewSplitDispatcher(testFormat, []interface{}{testfileWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -791,11 +791,11 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testConnWriter := newConnWriter("tcp", ":8888", false) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testConnWriter}) + testConnWriter := NewConnWriter("tcp", ":8888", false) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testConnWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -807,11 +807,11 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testConnWriter = newConnWriter("tcp", ":8888", true) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testConnWriter}) + testConnWriter = NewConnWriter("tcp", ":8888", true) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{testConnWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -1000,14 +1000,14 @@ func getParserTests() []parserTest { ` - testExpected = new(logConfig) - testExpected.Constraints, _ = newMinMaxConstraints(TraceLvl, CriticalLvl) + testExpected = new(configForParsing) + testExpected.Constraints, _ = NewMinMaxConstraints(TraceLvl, CriticalLvl) testExpected.Exceptions = nil - testrollingFileWriterTime, _ = newRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalDaily, rollingNameModePrefix) - testbufferedWriter, _ = newBufferedWriter(testrollingFileWriterTime, 100500, 100) - testFormat, _ = newFormatter("%Level %Msg %File 123") - formattedWriter, _ = newFormattedWriter(testbufferedWriter, testFormat) - testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{formattedWriter}) + testrollingFileWriterTime, _ = NewRollingFileWriterTime(testLogFileName, rollingArchiveNone, "", 0, "2006-01-02T15:04:05Z07:00", rollingIntervalDaily, rollingNameModePrefix) + testbufferedWriter, _ = NewBufferedWriter(testrollingFileWriterTime, 100500, 100) + testFormat, _ = NewFormatter("%Level %Msg %File 123") + formattedWriter, _ = NewFormattedWriter(testbufferedWriter, testFormat) + testHeadSplitter, _ = NewSplitDispatcher(DefaultFormatter, []interface{}{formattedWriter}) testExpected.LogType = syncloggerTypeFromString testExpected.RootDispatcher = testHeadSplitter parserTests = append(parserTests, parserTest{testName, testConfig, testExpected, false, nil}) @@ -1021,7 +1021,7 @@ func getParserTests() []parserTest { // terms of performance, but a valid one in terms of comparison, because // every seelog dispatcher/receiver must have a valid String() func // that fully represents its internal parameters. -func configsAreEqual(conf1 *logConfig, conf2 interface{}) bool { +func configsAreEqual(conf1 *configForParsing, conf2 interface{}) bool { if conf1 == nil { return conf2 == nil } @@ -1029,12 +1029,12 @@ func configsAreEqual(conf1 *logConfig, conf2 interface{}) bool { return conf1 == nil } - // logConfig, ok := conf2 //.(*logConfig) + // configForParsing, ok := conf2 //.(*configForParsing) // if !ok { // return false // } - return fmt.Sprintf("%v", conf1) == fmt.Sprintf("%v", conf2) //logConfig) + return fmt.Sprintf("%v", conf1) == fmt.Sprintf("%v", conf2) //configForParsing) } func testLogFileFilter(fn string) bool { diff --git a/common_constraints.go b/common_constraints.go index 23b3dd2..7ec2fe5 100644 --- a/common_constraints.go +++ b/common_constraints.go @@ -41,8 +41,8 @@ type minMaxConstraints struct { max LogLevel } -// newMinMaxConstraints creates a new minMaxConstraints struct with the specified min and max levels. -func newMinMaxConstraints(min LogLevel, max LogLevel) (*minMaxConstraints, error) { +// NewMinMaxConstraints creates a new minMaxConstraints struct with the specified min and max levels. +func NewMinMaxConstraints(min LogLevel, max LogLevel) (*minMaxConstraints, error) { if min > max { return nil, fmt.Errorf("min level can't be greater than max. Got min: %d, max: %d", min, max) } @@ -72,8 +72,8 @@ type listConstraints struct { allowedLevels map[LogLevel]bool } -// newListConstraints creates a new listConstraints struct with the specified allowed levels. -func newListConstraints(allowList []LogLevel) (*listConstraints, error) { +// NewListConstraints creates a new listConstraints struct with the specified allowed levels. +func NewListConstraints(allowList []LogLevel) (*listConstraints, error) { if allowList == nil { return nil, errors.New("list can't be nil") } @@ -149,7 +149,7 @@ func (listConstr *listConstraints) AllowedLevels() map[LogLevel]bool { type offConstraints struct { } -func newOffConstraints() (*offConstraints, error) { +func NewOffConstraints() (*offConstraints, error) { return &offConstraints{}, nil } diff --git a/common_constraints_test.go b/common_constraints_test.go index 0f05b9d..bb9918e 100644 --- a/common_constraints_test.go +++ b/common_constraints_test.go @@ -29,7 +29,7 @@ import ( ) func TestInvalidminMaxConstraints(t *testing.T) { - constr, err := newMinMaxConstraints(CriticalLvl, WarnLvl) + constr, err := NewMinMaxConstraints(CriticalLvl, WarnLvl) if err == nil || constr != nil { t.Errorf("expected an error and a nil value for minmax constraints: min = %d, max = %d. Got: %v, %v", @@ -41,7 +41,7 @@ func TestInvalidminMaxConstraints(t *testing.T) { func TestInvalidLogLevels(t *testing.T) { var invalidMin uint8 = 123 var invalidMax uint8 = 124 - minMaxConstr, errMinMax := newMinMaxConstraints(LogLevel(invalidMin), LogLevel(invalidMax)) + minMaxConstr, errMinMax := NewMinMaxConstraints(LogLevel(invalidMin), LogLevel(invalidMax)) if errMinMax == nil || minMaxConstr != nil { t.Errorf("expected an error and a nil value for minmax constraints: min = %d, max = %d. Got: %v, %v", @@ -51,7 +51,7 @@ func TestInvalidLogLevels(t *testing.T) { invalidList := []LogLevel{145} - listConstr, errList := newListConstraints(invalidList) + listConstr, errList := NewListConstraints(invalidList) if errList == nil || listConstr != nil { t.Errorf("expected an error and a nil value for constraints list: %v. Got: %v, %v", @@ -64,7 +64,7 @@ func TestlistConstraintsWithDuplicates(t *testing.T) { duplicateList := []LogLevel{TraceLvl, DebugLvl, InfoLvl, WarnLvl, ErrorLvl, CriticalLvl, CriticalLvl, CriticalLvl} - listConstr, errList := newListConstraints(duplicateList) + listConstr, errList := NewListConstraints(duplicateList) if errList != nil || listConstr == nil { t.Errorf("expected a valid constraints list struct for: %v, got error: %v, value: %v", @@ -88,7 +88,7 @@ func TestlistConstraintsWithDuplicates(t *testing.T) { func TestlistConstraintsWithOffInList(t *testing.T) { offList := []LogLevel{TraceLvl, DebugLvl, Off} - listConstr, errList := newListConstraints(offList) + listConstr, errList := NewListConstraints(offList) if errList == nil || listConstr != nil { t.Errorf("expected an error and a nil value for constraints list with 'Off': %v. Got: %v, %v", @@ -115,7 +115,7 @@ var minMaxTests = []logLevelTestCase{ func TestValidminMaxConstraints(t *testing.T) { - constr, err := newMinMaxConstraints(InfoLvl, WarnLvl) + constr, err := NewMinMaxConstraints(InfoLvl, WarnLvl) if err != nil || constr == nil { t.Errorf("expected a valid constraints struct for minmax constraints: min = %d, max = %d. Got: %v, %v", @@ -146,7 +146,7 @@ var listTests = []logLevelTestCase{ func TestValidlistConstraints(t *testing.T) { validList := []LogLevel{TraceLvl, InfoLvl, WarnLvl, CriticalLvl} - constr, err := newListConstraints(validList) + constr, err := NewListConstraints(validList) if err != nil || constr == nil { t.Errorf("expected a valid constraints list struct for: %v. Got error: %v, value: %v", @@ -177,7 +177,7 @@ var offTests = []logLevelTestCase{ func TestValidListoffConstraints(t *testing.T) { validList := []LogLevel{Off} - constr, err := newListConstraints(validList) + constr, err := NewListConstraints(validList) if err != nil || constr == nil { t.Errorf("expected a valid constraints list struct for: %v. Got error: %v, value: %v", diff --git a/common_exception.go b/common_exception.go index 9b5ebe0..9acc275 100644 --- a/common_exception.go +++ b/common_exception.go @@ -37,9 +37,9 @@ var ( funcFormatValidator = regexp.MustCompile(`[a-zA-Z0-9_\*\.]*`) ) -// logLevelException represents an exceptional case used when you need some specific files or funcs to +// LogLevelException represents an exceptional case used when you need some specific files or funcs to // override general constraints and to use their own. -type logLevelException struct { +type LogLevelException struct { funcPatternParts []string filePatternParts []string @@ -49,13 +49,13 @@ type logLevelException struct { constraints logLevelConstraints } -// newLogLevelException creates a new exception. -func newLogLevelException(funcPattern string, filePattern string, constraints logLevelConstraints) (*logLevelException, error) { +// NewLogLevelException creates a new exception. +func NewLogLevelException(funcPattern string, filePattern string, constraints logLevelConstraints) (*LogLevelException, error) { if constraints == nil { return nil, errors.New("constraints can not be nil") } - exception := new(logLevelException) + exception := new(LogLevelException) err := exception.initFuncPatternParts(funcPattern) if err != nil { @@ -74,28 +74,28 @@ func newLogLevelException(funcPattern string, filePattern string, constraints lo return exception, nil } -// MatchesContext returns true if context matches the patterns of this logLevelException -func (logLevelEx *logLevelException) MatchesContext(context LogContextInterface) bool { +// MatchesContext returns true if context matches the patterns of this LogLevelException +func (logLevelEx *LogLevelException) MatchesContext(context LogContextInterface) bool { return logLevelEx.match(context.Func(), context.FullPath()) } -// IsAllowed returns true if log level is allowed according to the constraints of this logLevelException -func (logLevelEx *logLevelException) IsAllowed(level LogLevel) bool { +// IsAllowed returns true if log level is allowed according to the constraints of this LogLevelException +func (logLevelEx *LogLevelException) IsAllowed(level LogLevel) bool { return logLevelEx.constraints.IsAllowed(level) } // FuncPattern returns the function pattern of a exception -func (logLevelEx *logLevelException) FuncPattern() string { +func (logLevelEx *LogLevelException) FuncPattern() string { return logLevelEx.funcPattern } // FuncPattern returns the file pattern of a exception -func (logLevelEx *logLevelException) FilePattern() string { +func (logLevelEx *LogLevelException) FilePattern() string { return logLevelEx.filePattern } // initFuncPatternParts checks whether the func filter has a correct format and splits funcPattern on parts -func (logLevelEx *logLevelException) initFuncPatternParts(funcPattern string) (err error) { +func (logLevelEx *LogLevelException) initFuncPatternParts(funcPattern string) (err error) { if funcFormatValidator.FindString(funcPattern) != funcPattern { return errors.New("func path \"" + funcPattern + "\" contains incorrect symbols. Only a-z A-Z 0-9 _ * . allowed)") @@ -106,7 +106,7 @@ func (logLevelEx *logLevelException) initFuncPatternParts(funcPattern string) (e } // Checks whether the file filter has a correct format and splits file patterns using splitPattern. -func (logLevelEx *logLevelException) initFilePatternParts(filePattern string) (err error) { +func (logLevelEx *LogLevelException) initFilePatternParts(filePattern string) (err error) { if fileFormatValidator.FindString(filePattern) != filePattern { return errors.New("file path \"" + filePattern + "\" contains incorrect symbols. Only a-z A-Z 0-9 \\ / _ * . allowed)") @@ -116,15 +116,15 @@ func (logLevelEx *logLevelException) initFilePatternParts(filePattern string) (e return err } -func (logLevelEx *logLevelException) match(funcPath string, filePath string) bool { +func (logLevelEx *LogLevelException) match(funcPath string, filePath string) bool { if !stringMatchesPattern(logLevelEx.funcPatternParts, funcPath) { return false } return stringMatchesPattern(logLevelEx.filePatternParts, filePath) } -func (logLevelEx *logLevelException) String() string { - str := fmt.Sprintf("Func: %s File: %s ", logLevelEx.funcPattern, logLevelEx.filePattern) +func (logLevelEx *LogLevelException) String() string { + str := fmt.Sprintf("Func: %s File: %s", logLevelEx.funcPattern, logLevelEx.filePattern) if logLevelEx.constraints != nil { str += fmt.Sprintf("Constr: %s", logLevelEx.constraints) diff --git a/common_exception_test.go b/common_exception_test.go index 4bff961..d98c280 100644 --- a/common_exception_test.go +++ b/common_exception_test.go @@ -53,14 +53,14 @@ var exceptionTestCases = []exceptionTestCase{ } func TestMatchingCorrectness(t *testing.T) { - constraints, err := newListConstraints([]LogLevel{TraceLvl}) + constraints, err := NewListConstraints([]LogLevel{TraceLvl}) if err != nil { t.Error(err) return } for _, testCase := range exceptionTestCases { - rule, ruleError := newLogLevelException(testCase.funcPattern, testCase.filePattern, constraints) + rule, ruleError := NewLogLevelException(testCase.funcPattern, testCase.filePattern, constraints) if ruleError != nil { t.Fatalf("Unexpected error on rule creation: [ %v, %v ]. %v", testCase.funcPattern, testCase.filePattern, ruleError) @@ -75,13 +75,13 @@ func TestMatchingCorrectness(t *testing.T) { } func TestAsterisksReducing(t *testing.T) { - constraints, err := newListConstraints([]LogLevel{TraceLvl}) + constraints, err := NewListConstraints([]LogLevel{TraceLvl}) if err != nil { t.Error(err) return } - rule, err := newLogLevelException("***func**", "fi*****le", constraints) + rule, err := NewLogLevelException("***func**", "fi*****le", constraints) if err != nil { t.Error(err) return diff --git a/dispatch_custom.go b/dispatch_custom.go index 7c13b67..383a770 100644 --- a/dispatch_custom.go +++ b/dispatch_custom.go @@ -151,9 +151,9 @@ type customReceiverDispatcher struct { usedArgs CustomReceiverInitArgs } -// newCustomReceiverDispatcher creates a customReceiverDispatcher which dispatches data to a specific receiver created +// NewCustomReceiverDispatcher creates a customReceiverDispatcher which dispatches data to a specific receiver created // using a tag in the config file. -func newCustomReceiverDispatcher(formatter *formatter, customReceiverName string, cArgs CustomReceiverInitArgs) (*customReceiverDispatcher, error) { +func NewCustomReceiverDispatcher(formatter *formatter, customReceiverName string, cArgs CustomReceiverInitArgs) (*customReceiverDispatcher, error) { if formatter == nil { return nil, errors.New("formatter cannot be nil") } @@ -174,9 +174,9 @@ func newCustomReceiverDispatcher(formatter *formatter, customReceiverName string return disp, nil } -// newCustomReceiverDispatcherByValue is basically the same as newCustomReceiverDispatcher, but using +// NewCustomReceiverDispatcherByValue is basically the same as NewCustomReceiverDispatcher, but using // a specific CustomReceiver value instead of instantiating a new one by type. -func newCustomReceiverDispatcherByValue(formatter *formatter, customReceiver CustomReceiver, name string, cArgs CustomReceiverInitArgs) (*customReceiverDispatcher, error) { +func NewCustomReceiverDispatcherByValue(formatter *formatter, customReceiver CustomReceiver, name string, cArgs CustomReceiverInitArgs) (*customReceiverDispatcher, error) { if formatter == nil { return nil, errors.New("formatter cannot be nil") } diff --git a/dispatch_customdispatcher_test.go b/dispatch_customdispatcher_test.go index d86f8b9..23f631a 100644 --- a/dispatch_customdispatcher_test.go +++ b/dispatch_customdispatcher_test.go @@ -36,7 +36,7 @@ func TestCustomDispatcher_Message(t *testing.T) { recName := "TestCustomDispatcher_Message" RegisterReceiver(recName, &testCustomDispatcherMessageReceiver{}) - customDispatcher, err := newCustomReceiverDispatcher(onlyMessageFormatForTest, recName, CustomReceiverInitArgs{ + customDispatcher, err := NewCustomReceiverDispatcher(onlyMessageFormatForTest, recName, CustomReceiverInitArgs{ XmlCustomAttrs: map[string]string{ "test": "testdata", }, @@ -90,7 +90,7 @@ func TestCustomDispatcher_Flush(t *testing.T) { recName := "TestCustomDispatcher_Flush" RegisterReceiver(recName, &testCustomDispatcherFlushReceiver{}) - customDispatcher, err := newCustomReceiverDispatcher(onlyMessageFormatForTest, recName, CustomReceiverInitArgs{ + customDispatcher, err := NewCustomReceiverDispatcher(onlyMessageFormatForTest, recName, CustomReceiverInitArgs{ XmlCustomAttrs: map[string]string{ "test": "testdata", }, @@ -137,7 +137,7 @@ func TestCustomDispatcher_Close(t *testing.T) { recName := "TestCustomDispatcher_Close" RegisterReceiver(recName, &testCustomDispatcherCloseReceiver{}) - customDispatcher, err := newCustomReceiverDispatcher(onlyMessageFormatForTest, recName, CustomReceiverInitArgs{ + customDispatcher, err := NewCustomReceiverDispatcher(onlyMessageFormatForTest, recName, CustomReceiverInitArgs{ XmlCustomAttrs: map[string]string{ "test": "testdata", }, diff --git a/dispatch_dispatcher.go b/dispatch_dispatcher.go index e3c6955..2bd3b4a 100644 --- a/dispatch_dispatcher.go +++ b/dispatch_dispatcher.go @@ -66,7 +66,7 @@ func createDispatcher(formatter *formatter, receivers []interface{}) (*dispatche ioWriter, ok := receiver.(io.Writer) if ok { - writer, err := newFormattedWriter(ioWriter, disp.formatter) + writer, err := NewFormattedWriter(ioWriter, disp.formatter) if err != nil { return nil, err } diff --git a/dispatch_filterdispatcher.go b/dispatch_filterdispatcher.go index 60da31f..9de8a72 100644 --- a/dispatch_filterdispatcher.go +++ b/dispatch_filterdispatcher.go @@ -35,8 +35,8 @@ type filterDispatcher struct { allowList map[LogLevel]bool } -// newFilterDispatcher creates a new filterDispatcher using a list of allowed levels. -func newFilterDispatcher(formatter *formatter, receivers []interface{}, allowList ...LogLevel) (*filterDispatcher, error) { +// NewFilterDispatcher creates a new filterDispatcher using a list of allowed levels. +func NewFilterDispatcher(formatter *formatter, receivers []interface{}, allowList ...LogLevel) (*filterDispatcher, error) { disp, err := createDispatcher(formatter, receivers) if err != nil { return nil, err diff --git a/dispatch_filterdispatcher_test.go b/dispatch_filterdispatcher_test.go index 9bd6763..c1894a7 100644 --- a/dispatch_filterdispatcher_test.go +++ b/dispatch_filterdispatcher_test.go @@ -30,7 +30,7 @@ import ( func TestfilterDispatcher_Pass(t *testing.T) { writer, _ := newBytesVerifier(t) - filter, err := newFilterDispatcher(onlyMessageFormatForTest, []interface{}{writer}, TraceLvl) + filter, err := NewFilterDispatcher(onlyMessageFormatForTest, []interface{}{writer}, TraceLvl) if err != nil { t.Error(err) return @@ -50,7 +50,7 @@ func TestfilterDispatcher_Pass(t *testing.T) { func TestfilterDispatcher_Deny(t *testing.T) { writer, _ := newBytesVerifier(t) - filter, err := newFilterDispatcher(defaultformatter, []interface{}{writer}) + filter, err := NewFilterDispatcher(DefaultFormatter, []interface{}{writer}) if err != nil { t.Error(err) return diff --git a/dispatch_splitdispatcher.go b/dispatch_splitdispatcher.go index 218729c..1d0fe7e 100644 --- a/dispatch_splitdispatcher.go +++ b/dispatch_splitdispatcher.go @@ -33,7 +33,7 @@ type splitDispatcher struct { *dispatcher } -func newSplitDispatcher(formatter *formatter, receivers []interface{}) (*splitDispatcher, error) { +func NewSplitDispatcher(formatter *formatter, receivers []interface{}) (*splitDispatcher, error) { disp, err := createDispatcher(formatter, receivers) if err != nil { return nil, err diff --git a/dispatch_splitdispatcher_test.go b/dispatch_splitdispatcher_test.go index bf18e95..fc4651c 100644 --- a/dispatch_splitdispatcher_test.go +++ b/dispatch_splitdispatcher_test.go @@ -33,7 +33,7 @@ var onlyMessageFormatForTest *formatter func init() { var err error - onlyMessageFormatForTest, err = newFormatter("%Msg") + onlyMessageFormatForTest, err = NewFormatter("%Msg") if err != nil { fmt.Println("Can not create only message format: " + err.Error()) } @@ -42,7 +42,7 @@ func init() { func TestsplitDispatcher(t *testing.T) { writer1, _ := newBytesVerifier(t) writer2, _ := newBytesVerifier(t) - spliter, err := newSplitDispatcher(onlyMessageFormatForTest, []interface{}{writer1, writer2}) + spliter, err := NewSplitDispatcher(onlyMessageFormatForTest, []interface{}{writer1, writer2}) if err != nil { t.Error(err) return diff --git a/doc.go b/doc.go index 95c15ae..2734c9c 100644 --- a/doc.go +++ b/doc.go @@ -92,8 +92,7 @@ This way you are able to use package level funcs instead of passing the logger v Configuration -Main seelog point is to configure logger via config files and not the code. So you can only specify -formats and log rules by changing the configuration. +Main seelog point is to configure logger via config files and not the code. The configuration is read by LoggerFrom* funcs. These funcs read xml configuration from different sources and try to create a logger using it. @@ -133,6 +132,41 @@ logs to console, all.log, and errors.log depending on the log level. Its output use log level 'debug' and higher (minlevel is set) for all files with names that don't start with 'test'. For files starting with 'test' this logger prohibits all levels below 'error'. +Configuration using code + +Although configuration using code is not recommended, it is sometimes needed and it is possible to do with seelog. Basically, what +you need to do to get started is to create constraints, exceptions and a dispatcher tree (same as with config). Most of the New* +functions in this package are used to provide such capabilities. + +Here is an example of configuration in code, that demonstrates an async loop logger that logs to a simple split dispatcher with +a console receiver using a specified format and is filtered using a top-level min-max constraints and one expection for +the 'main.go' file. So, this is basically a demonstration of configuration of most of the features: + + package main + + import log "github.com/cihub/seelog" + + func main() { + defer log.Flush() + log.Info("Hello from Seelog!") + + consoleWriter, _ := log.NewConsoleWriter() + formatter, _ := log.NewFormatter("%Level %Msg %File%n") + root, _ := log.NewSplitDispatcher(formatter, []interface{}{consoleWriter}) + constraints, _ := log.NewMinMaxConstraints(log.TraceLvl, log.CriticalLvl) + specificConstraints, _ := log.NewListConstraints([]log.LogLevel{log.InfoLvl, log.ErrorLvl}) + ex, _ := log.NewLogLevelException("*", "*main.go", specificConstraints) + exceptions := []*log.LogLevelException{ex} + + logger := log.NewAsyncLoopLogger(log.NewLoggerConfig(constraints, exceptions, root)) + log.ReplaceLogger(logger) + + log.Trace("This should not be seen") + log.Debug("This should not be seen") + log.Info("Test") + log.Error("Test2") + } + Examples To learn seelog features faster you should check the examples package: https://github.com/cihub/seelog-examples diff --git a/format.go b/format.go index b71994e..32682f3 100644 --- a/format.go +++ b/format.go @@ -53,16 +53,16 @@ const ( var DefaultMsgFormat = "%Ns [%Level] %Msg%n" var ( - defaultformatter *formatter + DefaultFormatter *formatter msgonlyformatter *formatter ) func init() { var err error - if defaultformatter, err = newFormatter(DefaultMsgFormat); err != nil { - reportInternalError(fmt.Errorf("error during creating defaultformatter: %s", err)) + if DefaultFormatter, err = NewFormatter(DefaultMsgFormat); err != nil { + reportInternalError(fmt.Errorf("error during creating DefaultFormatter: %s", err)) } - if msgonlyformatter, err = newFormatter("%Msg"); err != nil { + if msgonlyformatter, err = NewFormatter("%Msg"); err != nil { reportInternalError(fmt.Errorf("error during creating msgonlyformatter: %s", err)) } } @@ -147,8 +147,8 @@ type formatter struct { formatterFuncs []FormatterFunc } -// newFormatter creates a new formatter using a format string -func newFormatter(formatString string) (*formatter, error) { +// NewFormatter creates a new formatter using a format string +func NewFormatter(formatString string) (*formatter, error) { fmtr := new(formatter) fmtr.fmtStringOriginal = formatString if err := buildFormatterFuncs(fmtr); err != nil { diff --git a/format_test.go b/format_test.go index 6e1e14c..dd61bdf 100644 --- a/format_test.go +++ b/format_test.go @@ -135,7 +135,7 @@ func TestFormats(t *testing.T) { for _, test := range formatTests { - form, err := newFormatter(test.formatString) + form, err := NewFormatter(test.formatString) if (err != nil) != test.errorExpected { t.Errorf("input: %s \nInput LL: %s\n* Expected error:%t Got error: %t\n", @@ -158,7 +158,7 @@ func TestFormats(t *testing.T) { } func TestDateFormat(t *testing.T) { - _, err := newFormatter("%Date") + _, err := NewFormatter("%Date") if err != nil { t.Error("Unexpected error: " + err.Error()) } @@ -174,7 +174,7 @@ func TestDateParameterizedFormat(t *testing.T) { return } - form, err := newFormatter("%Date(" + preciseForamt + ")") + form, err := NewFormatter("%Date(" + preciseForamt + ")") if err != nil { t.Error("Unexpected error: " + err.Error()) } @@ -187,7 +187,7 @@ func TestDateParameterizedFormat(t *testing.T) { t.Errorf("incorrect message: %v. Expected %v or %v", msg, dateBefore, dateAfter) } - _, err = newFormatter("%Date(" + preciseForamt) + _, err = NewFormatter("%Date(" + preciseForamt) if err == nil { t.Error("Expected error for invalid format") } @@ -223,7 +223,7 @@ func TestCustomFormatterRegistration(t *testing.T) { return } - form, err := newFormatter("%Msg %TEST 123") + form, err := NewFormatter("%Msg %TEST 123") if err != nil { t.Fatalf("%s\n", err.Error()) } diff --git a/log.go b/log.go index 1ec6880..f775e1f 100644 --- a/log.go +++ b/log.go @@ -66,11 +66,11 @@ func init() { Current = Default } -func createLoggerFromConfig(config *logConfig) (LoggerInterface, error) { +func createLoggerFromFullConfig(config *configForParsing) (LoggerInterface, error) { if config.LogType == syncloggerTypeFromString { - return newSyncLogger(config), nil + return NewSyncLogger(&config.logConfig), nil } else if config.LogType == asyncLooploggerTypeFromString { - return newAsyncLoopLogger(config), nil + return NewAsyncLoopLogger(&config.logConfig), nil } else if config.LogType == asyncTimerloggerTypeFromString { logData := config.LoggerData if logData == nil { @@ -82,7 +82,7 @@ func createLoggerFromConfig(config *logConfig) (LoggerInterface, error) { return nil, errors.New("invalid async timer data") } - logger, err := newAsyncTimerLogger(config, time.Duration(asyncInt.AsyncInterval)) + logger, err := NewAsyncTimerLogger(&config.logConfig, time.Duration(asyncInt.AsyncInterval)) if !ok { return nil, err } @@ -99,8 +99,8 @@ func createLoggerFromConfig(config *logConfig) (LoggerInterface, error) { return nil, errors.New("invalid adaptive logger parameters") } - logger, err := newAsyncAdaptiveLogger( - config, + logger, err := NewAsyncAdaptiveLogger( + &config.logConfig, time.Duration(adaptData.MinInterval), time.Duration(adaptData.MaxInterval), adaptData.CriticalMsgCount, diff --git a/writers_bufferedwriter.go b/writers_bufferedwriter.go index e35e340..37d75c8 100644 --- a/writers_bufferedwriter.go +++ b/writers_bufferedwriter.go @@ -42,10 +42,10 @@ type bufferedWriter struct { bufferSize int // max size of data chunk in bytes } -// newBufferedWriter creates a new buffered writer struct. +// NewBufferedWriter creates a new buffered writer struct. // bufferSize -- size of memory buffer in bytes // flushPeriod -- period in which data flushes from memory buffer in milliseconds. 0 - turn off this functionality -func newBufferedWriter(innerWriter io.Writer, bufferSize int, flushPeriod time.Duration) (*bufferedWriter, error) { +func NewBufferedWriter(innerWriter io.Writer, bufferSize int, flushPeriod time.Duration) (*bufferedWriter, error) { if innerWriter == nil { return nil, errors.New("argument is nil: innerWriter") diff --git a/writers_bufferedwriter_test.go b/writers_bufferedwriter_test.go index 42d7f28..03f74f7 100644 --- a/writers_bufferedwriter_test.go +++ b/writers_bufferedwriter_test.go @@ -30,7 +30,7 @@ import ( func TestChunkWriteOnFilling(t *testing.T) { writer, _ := newBytesVerifier(t) - bufferedWriter, err := newBufferedWriter(writer, 1024, 0) + bufferedWriter, err := NewBufferedWriter(writer, 1024, 0) if err != nil { t.Fatalf("Unexpected buffered writer creation error: %s", err.Error()) @@ -45,7 +45,7 @@ func TestChunkWriteOnFilling(t *testing.T) { func TestFlushByTimePeriod(t *testing.T) { writer, _ := newBytesVerifier(t) - bufferedWriter, err := newBufferedWriter(writer, 1024, 10) + bufferedWriter, err := NewBufferedWriter(writer, 1024, 10) if err != nil { t.Fatalf("Unexpected buffered writer creation error: %s", err.Error()) @@ -61,7 +61,7 @@ func TestFlushByTimePeriod(t *testing.T) { func TestBigMessageMustPassMemoryBuffer(t *testing.T) { writer, _ := newBytesVerifier(t) - bufferedWriter, err := newBufferedWriter(writer, 1024, 0) + bufferedWriter, err := NewBufferedWriter(writer, 1024, 0) if err != nil { t.Fatalf("Unexpected buffered writer creation error: %s", err.Error()) diff --git a/writers_connwriter.go b/writers_connwriter.go index b7b360b..d199894 100644 --- a/writers_connwriter.go +++ b/writers_connwriter.go @@ -44,7 +44,7 @@ type connWriter struct { // Creates writer to the address addr on the network netName. // Connection will be opened on each write if reconnectOnMsg = true -func newConnWriter(netName string, addr string, reconnectOnMsg bool) *connWriter { +func NewConnWriter(netName string, addr string, reconnectOnMsg bool) *connWriter { newWriter := new(connWriter) newWriter.net = netName diff --git a/writers_consolewriter.go b/writers_consolewriter.go index f0d3b41..3eb79af 100644 --- a/writers_consolewriter.go +++ b/writers_consolewriter.go @@ -31,7 +31,7 @@ type consoleWriter struct { } // Creates a new console writer. Returns error, if the console writer couldn't be created. -func newConsoleWriter() (writer *consoleWriter, err error) { +func NewConsoleWriter() (writer *consoleWriter, err error) { newWriter := new(consoleWriter) return newWriter, nil diff --git a/writers_filewriter.go b/writers_filewriter.go index be5ec34..8d3ae27 100644 --- a/writers_filewriter.go +++ b/writers_filewriter.go @@ -38,7 +38,7 @@ type fileWriter struct { } // Creates a new file and a corresponding writer. Returns error, if the file couldn't be created. -func newFileWriter(fileName string) (writer *fileWriter, err error) { +func NewFileWriter(fileName string) (writer *fileWriter, err error) { newWriter := new(fileWriter) newWriter.fileName = fileName diff --git a/writers_filewriter_test.go b/writers_filewriter_test.go index 5f73a28..1893be8 100644 --- a/writers_filewriter_test.go +++ b/writers_filewriter_test.go @@ -41,13 +41,13 @@ var bytesFileTest = []byte(strings.Repeat("A", messageLen)) func TestSimpleFileWriter(t *testing.T) { t.Logf("Starting file writer tests") - newFileWriterTester(simplefileWriterTests, simplefileWriterGetter, t).test() + NewFileWriterTester(simplefileWriterTests, simplefileWriterGetter, t).test() } //=============================================================== func simplefileWriterGetter(testCase *fileWriterTestCase) (io.WriteCloser, error) { - return newFileWriter(testCase.fileName) + return NewFileWriter(testCase.fileName) } //=============================================================== @@ -81,7 +81,7 @@ type fileWriterTester struct { t *testing.T } -func newFileWriterTester( +func NewFileWriterTester( testCases []*fileWriterTestCase, writerGetter func(*fileWriterTestCase) (io.WriteCloser, error), t *testing.T) *fileWriterTester { diff --git a/writers_formattedwriter.go b/writers_formattedwriter.go index d28f2b8..bf44a41 100644 --- a/writers_formattedwriter.go +++ b/writers_formattedwriter.go @@ -35,7 +35,7 @@ type formattedWriter struct { formatter *formatter } -func newFormattedWriter(writer io.Writer, formatter *formatter) (*formattedWriter, error) { +func NewFormattedWriter(writer io.Writer, formatter *formatter) (*formattedWriter, error) { if formatter == nil { return nil, errors.New("formatter can not be nil") } diff --git a/writers_formattedwriter_test.go b/writers_formattedwriter_test.go index 0ba0d49..351ac4e 100644 --- a/writers_formattedwriter_test.go +++ b/writers_formattedwriter_test.go @@ -39,13 +39,13 @@ func TestformattedWriter(t *testing.T) { return } - formatter, err := newFormatter(formatStr) + formatter, err := NewFormatter(formatStr) if err != nil { t.Error(err) return } - writer, err := newFormattedWriter(bytesVerifier, formatter) + writer, err := NewFormattedWriter(bytesVerifier, formatter) if err != nil { t.Error(err) return diff --git a/writers_rollingfilewriter.go b/writers_rollingfilewriter.go index 5b321d5..e7bfad4 100644 --- a/writers_rollingfilewriter.go +++ b/writers_rollingfilewriter.go @@ -447,7 +447,7 @@ type rollingFileWriterSize struct { maxFileSize int64 } -func newRollingFileWriterSize(fpath string, atype rollingArchiveType, apath string, maxSize int64, maxRolls int, namemode rollingNameMode) (*rollingFileWriterSize, error) { +func NewRollingFileWriterSize(fpath string, atype rollingArchiveType, apath string, maxSize int64, maxRolls int, namemode rollingNameMode) (*rollingFileWriterSize, error) { rw, err := newRollingFileWriter(fpath, rollingTypeSize, atype, apath, maxRolls, namemode) if err != nil { return nil, err @@ -518,7 +518,7 @@ type rollingFileWriterTime struct { currentTimeFileName string } -func newRollingFileWriterTime(fpath string, atype rollingArchiveType, apath string, maxr int, +func NewRollingFileWriterTime(fpath string, atype rollingArchiveType, apath string, maxr int, timePattern string, interval rollingIntervalType, namemode rollingNameMode) (*rollingFileWriterTime, error) { rw, err := newRollingFileWriter(fpath, rollingTypeTime, atype, apath, maxr, namemode) diff --git a/writers_rollingfilewriter_test.go b/writers_rollingfilewriter_test.go index 338c3a4..9ca91ae 100644 --- a/writers_rollingfilewriter_test.go +++ b/writers_rollingfilewriter_test.go @@ -57,16 +57,16 @@ func createRollingDatefileWriterTestCase( func TestRollingFileWriter(t *testing.T) { t.Logf("Starting rolling file writer tests") - newFileWriterTester(rollingfileWriterTests, rollingFileWriterGetter, t).test() + NewFileWriterTester(rollingfileWriterTests, rollingFileWriterGetter, t).test() } //=============================================================== func rollingFileWriterGetter(testCase *fileWriterTestCase) (io.WriteCloser, error) { if testCase.rollingType == rollingTypeSize { - return newRollingFileWriterSize(testCase.fileName, rollingArchiveNone, "", testCase.fileSize, testCase.maxRolls, testCase.nameMode) + return NewRollingFileWriterSize(testCase.fileName, rollingArchiveNone, "", testCase.fileSize, testCase.maxRolls, testCase.nameMode) } else if testCase.rollingType == rollingTypeTime { - return newRollingFileWriterTime(testCase.fileName, rollingArchiveNone, "", -1, testCase.datePattern, rollingIntervalDaily, testCase.nameMode) + return NewRollingFileWriterTime(testCase.fileName, rollingArchiveNone, "", -1, testCase.datePattern, rollingIntervalDaily, testCase.nameMode) } return nil, fmt.Errorf("incorrect rollingType") diff --git a/writers_smtpwriter.go b/writers_smtpwriter.go index d9de607..31b7943 100644 --- a/writers_smtpwriter.go +++ b/writers_smtpwriter.go @@ -57,8 +57,8 @@ type smtpWriter struct { subject string } -// newSMTPWriter returns a new SMTP-writer. -func newSMTPWriter(sa, sn string, ras []string, hn, hp, un, pwd string, cacdps []string, subj string, headers []string) *smtpWriter { +// NewSMTPWriter returns a new SMTP-writer. +func NewSMTPWriter(sa, sn string, ras []string, hn, hp, un, pwd string, cacdps []string, subj string, headers []string) *smtpWriter { return &smtpWriter{ auth: smtp.PlainAuth("", un, pwd, hn), hostName: hn,