<commit_before>// Copyright 2018 <<EMAIL>{AT}<EMAIL>>. All rights reserved.
// Use of this source code is governed by a Apache-style
// license that can be found in the LICENSE file.

// copy from https://github.com/chai2010/logger

package libconfd

import (
	"fmt"
	"io"
	"log"
	"os"
	"sync/atomic"
)

var pkgLogger atomic.Value

func init() {
	SetLogger(NewStdLogger(os.Stderr, "", "", 0))
}

// NewStdLogger create new logger based on std log.
// If level is empty string, use WARN as the default level.
// If flag is zore, use 'log.LstdFlags|log.Lshortfile' as the default flag.
// Level: DEBUG < INFO < WARN < ERROR < PANIC < FATAL
func NewStdLogger(out io.Writer, prefix, level string, flag int) Logger {
	return newStdLogger(out, prefix, level, flag)
}

func GetLogger() Logger {
	return pkgLogger.Load().(Logger)
}

func SetLogger(new Logger) (old Logger) {
	if x := pkgLogger.Load(); x != nil {
		old = x.(Logger)
	}
	pkgLogger.Store(new)
	return
}

// Logger interface
//
// See https://github.com/chai2010/logger
type Logger interface {
	Assert(condition bool, v ...interface{})
	Assertln(condition bool, v ...interface{})
	Assertf(condition bool, format string, v ...interface{})
	Debug(v ...interface{})
	Debugln(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infoln(v ...interface{})
	Infof(format string, v ...interface{})
	Warning(v ...interface{})
	Warningln(v ...interface{})
	Warningf(format string, v ...interface{})
	Error(v ...interface{})
	Errorln(v ...interface{})
	Errorf(format string, v ...interface{})
	Panic(v ...interface{})
	Panicln(v ...interface{})
	Panicf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalln(v ...interface{})
	Fatalf(format string, v ...interface{})

	// Level: DEBUG < INFO < WARN < ERROR < PANIC < FATAL
	GetLevel() string
	SetLevel(new string) (old string)
}

type logLevelType uint32

const (
	logUnknownLevel logLevelType = iota // invalid
	logDebugLevel
	logInfoLevel
	logWarnLevel
	logErrorLevel
	logPanicLevel
	logFatalLevel
)

func (level logLevelType) Valid() bool {
	return level >= logDebugLevel && level <= logFatalLevel
}

func newLogLevel(name string) logLevelType {
	switch name {
	case "DEBUG", "":
		return logDebugLevel
	case "INFO":
		return logInfoLevel
	case "WARN":
		return logWarnLevel
	case "ERROR":
		return logErrorLevel
	case "PANIC":
		return logPanicLevel
	case "FATAL":
		return logFatalLevel
	}
	return logUnknownLevel
}
<commit_msg>fix log level caps error<commit_after>// Copyright 2018 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a Apache-style
// license that can be found in the LICENSE file.

// copy from https://github.com/chai2010/logger

package libconfd

import (
	"fmt"
	"io"
	"log"
	"os"
	"strings"
	"sync/atomic"
)

var pkgLogger atomic.Value

func init() {
	SetLogger(NewStdLogger(os.Stderr, "", "", 0))
}

// NewStdLogger create new logger based on std log.
// If level is empty string, use WARN as the default level.
// If flag is zore, use 'log.LstdFlags|log.Lshortfile' as the default flag.
// Level: DEBUG < INFO < WARN < ERROR < PANIC < FATAL
func NewStdLogger(out io.Writer, prefix, level string, flag int) Logger {
	return newStdLogger(out, prefix, level, flag)
}

func GetLogger() Logger {
	return pkgLogger.Load().(Logger)
}

func SetLogger(new Logger) (old Logger) {
	if x := pkgLogger.Load(); x != nil {
		old = x.(Logger)
	}
	pkgLogger.Store(new)
	return
}

// Logger interface
//
// See https://github.com/chai2010/logger
type Logger interface {
	Assert(condition bool, v ...interface{})
	Assertln(condition bool, v ...interface{})
	Assertf(condition bool, format string, v ...interface{})
	Debug(v ...interface{})
	Debugln(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infoln(v ...interface{})
	Infof(format string, v ...interface{})
	Warning(v ...interface{})
	Warningln(v ...interface{})
	Warningf(format string, v ...interface{})
	Error(v ...interface{})
	Errorln(v ...interface{})
	Errorf(format string, v ...interface{})
	Panic(v ...interface{})
	Panicln(v ...interface{})
	Panicf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalln(v ...interface{})
	Fatalf(format string, v ...interface{})

	// Level: DEBUG < INFO < WARN < ERROR < PANIC < FATAL
	GetLevel() string
	SetLevel(new string) (old string)
}

type logLevelType uint32

const (
	logUnknownLevel logLevelType = iota // invalid
	logDebugLevel
	logInfoLevel
	logWarnLevel
	logErrorLevel
	logPanicLevel
	logFatalLevel
)

func (level logLevelType) Valid() bool {
	return level >= logDebugLevel && level <= logFatalLevel
}

func newLogLevel(name string) logLevelType {
	switch strings.ToUpper(name) {
	case "DEBUG", "":
		return logDebugLevel
	case "INFO":
		return logInfoLevel
	case "WARN":
		return logWarnLevel
	case "ERROR":
		return logErrorLevel
	case "PANIC":
		return logPanicLevel
	case "FATAL":
		return logFatalLevel
	}
	return logUnknownLevel
}

{'fraction_non_alphanumeric': 0.1440320962888666, 'fraction_numerical': 0.006018054162487462, 'mean_word_length': 3.9123152709359608, 'pattern_counts': {'":': 12, '<': 29, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7449792', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1625, 'n_words': 507}