<commit_before>// Copyright 2017 The nvim-go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package logger

import (
	"fmt"
	"os"
	"strings"

	"github.com/fatih/color"
	prettyjson "github.com/hokaccha/go-prettyjson"
	"go.uber.org/zap"
	"go.uber.org/zap/buffer"
	"go.uber.org/zap/zapcore"
)

func init() {
	if err := zap.RegisterEncoder("debug", func(encoderConfig zapcore.EncoderConfig) (zapcore.Encoder, error) {
		return NewConsoleEncoder(encoderConfig), nil
	}); err != nil {
		panic(err)
	}
}

func NewZapLogger(opts ...zap.Option) *zap.Logger {
	debug := os.Getenv("NVIM_GO_DEBUG") != ""
	var cfg zap.Config
	if !debug {
		cfg = zap.NewProductionConfig()
		cfg.DisableStacktrace = true
		cfg.Level.SetLevel(zapcore.DPanicLevel) // not show logs normally
	} else {
		cfg = zap.NewDevelopmentConfig()
		cfg.Encoding = "debug" // already registered init function
		cfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
		opts = append(opts, zap.AddCaller())
	}
	cfg.EncoderConfig.EncodeTime = nil

	if level := os.Getenv("NVIM_GO_LOG_LEVEL"); level != "" {
		var lv zapcore.Level
		if err := lv.UnmarshalText([]byte(level)); err != nil {
			panic(fmt.Sprintf("unknown zap log level: %v", level))
		}
		cfg.Level.SetLevel(lv)
	}

	zapLogger, err := cfg.Build(opts...)
	if err != nil {
		panic(err)
	}
<commit_msg>logger: set some zap config to both of prod and debug<commit_after>// Copyright 2017 The nvim-go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package logger

import (
	"fmt"
	"os"
	"strings"

	"github.com/fatih/color"
	prettyjson "github.com/hokaccha/go-prettyjson"
	"go.uber.org/zap"
	"go.uber.org/zap/buffer"
	"go.uber.org/zap/zapcore"
)

func init() {
	if err := zap.RegisterEncoder("debug", func(encoderConfig zapcore.EncoderConfig) (zapcore.Encoder, error) {
		return NewConsoleEncoder(encoderConfig), nil
	}); err != nil {
		panic(err)
	}
}

func NewZapLogger(opts ...zap.Option) *zap.Logger {
	debug := os.Getenv("NVIM_GO_DEBUG") != ""
	var cfg zap.Config
	if !debug {
		cfg = zap.NewProductionConfig()
	} else {
		cfg = zap.NewDevelopmentConfig()
		cfg.Encoding = "debug" // already registered init function
		cfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
		opts = append(opts, zap.AddCaller())
	}

	cfg.DisableStacktrace = true
	cfg.EncoderConfig.EncodeTime = nil
	cfg.Level.SetLevel(zapcore.DPanicLevel) // not show logs normally

	if level := os.Getenv("NVIM_GO_LOG_LEVEL"); level != "" {
		var lv zapcore.Level
		if err := lv.UnmarshalText([]byte(level)); err != nil {
			panic(fmt.Sprintf("unknown zap log level: %v", level))
		}
		cfg.Level.SetLevel(lv)
	}

	zapLogger, err := cfg.Build(opts...)
	if err != nil {
		panic(err)
	}

{'fraction_non_alphanumeric': 0.14136125654450263, 'fraction_numerical': 0.002792321116928447, 'mean_word_length': 3.9413793103448276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '769692', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1026, 'n_words': 244}