// NewJSONFileLogger builds a Sender instance that write JSON
// formated log messages to a file, with one-line per message. The
// JSON formated message is taken by calling the Raw() method on the
// message.Composer and Marshalling the results.
182667
func NewJSONFileLogger(name, file string, l LevelInfo) (Sender, error) {
	s, err := MakeJSONFileLogger(file)
	if err != nil {
		return nil, err
	}

	return setup(s, name, l)
}
1100482
func NewLogger(writer io.Writer, name string) Logger {
	formatter, err := createFormatter(name, logxiFormat)
	if err != nil {
		panic("Could not create formatter")
	}
	return NewLogger3(writer, name, formatter)
}
1259255
func New(opts *LoggerOptions) Logger {
	if opts == nil {
		opts = &LoggerOptions{}
	}

	output := opts.Output
	if output == nil {
		output = DefaultOutput
	}

	level := opts.Level
	if level == NoLevel {
		level = DefaultLevel
	}

	mutex := opts.Mutex
	if mutex == nil {
		mutex = new(sync.Mutex)
	}

	l := &intLogger{
		json:       opts.JSONFormat,
		caller:     opts.IncludeLocation,
		name:       opts.Name,
		timeFormat: TimeFormat,
		mutex:      mutex,
		writer:     newWriter(output),
		level:      new(int32),
	}

	if opts.TimeFormat != "" {
		l.timeFormat = opts.TimeFormat
	}

	atomic.StoreInt32(l.level, int32(level))

	return l
}
1064401
func NewJSONLogger(cfg *LogConfig, writer io.Writer) *JSONLogger {
	l := &JSONLogger{json.NewEncoder(writer), cfg}
	if l.cfg == nil {
		l.cfg = &LogConfig{}
	}
	return l
}
1159290
func createLogger(name string, level Level, format string, timeFormat string, out io.Writer, sync bool) (*Logger, error) {
	return createCustomizedLogger(name, level, format, timeFormat, out, sync, DefaultQueueSize, DefaultRequestSize, DefaultBufferSize, DefaultTimeInterval)
}
729295
func NewLogger() *Logger {
	l := &Logger{}
	l.base.SetPrefix("")
	l.base.SetFlags(log.Lmicroseconds | log.Lshortfile)
	l.SetLevel(LDebug, LInfo, LWarn, LError, LFatal)
	l.SetWriter(os.Stderr)
	return l
}
142765
func newFileWriter() *fileLogWriter {
	w := &fileLogWriter{
		Daily:      true,
		MaxDays:    7,
		Rotate:     true,
		RotatePerm: "0440",
		Level:      LevelDebug,
		Perm:       "0660",
	}
	return w
}
774873
func NewLogFile(sfile *tsdb.SeriesFile, path string) *LogFile {
	return &LogFile{
		sfile: sfile,
		path:  path,
		mms:   make(logMeasurements),
		stats: make(MeasurementCardinalityStats),

		seriesIDSet:          tsdb.NewSeriesIDSet(),
		tombstoneSeriesIDSet: tsdb.NewSeriesIDSet(),
	}
}
228859
func writeCheckedJSON(r io.ReadCloser, fileName string) error {
	return writeCheckedFile(r, fileName, func(r io.Reader) error {
		d := json.NewDecoder(r)
		tmp := map[string]interface{}{}
		return d.Decode(&tmp)
	})
	return nil
}
1066106
func NewLogger(component string, options ...zap.Option) Logger {
	enc := zap.NewJSONEncoder(
		zap.LevelString("log_level"),
		zap.MessageKey("message"),
		zap.EpochFormatter("timestamp"),
		numberLevelFormatter(),
	)
	origLogger := zap.New(enc, options...)

	return &logger{
		source:     component,
		origLogger: origLogger,
		Logger:     origLogger.With(zap.String("source", component)),
	}
}
23483
func NewLogger() dlog.Logger {
	return dlog.NewLogger(
		glog.Infoln,
		map[dlog.Level]func(...interface{}){
			dlog.LevelDebug: glog.Infoln,
			dlog.LevelInfo:  glog.Infoln,
			dlog.LevelWarn:  glog.Warningln,
			dlog.LevelError: glog.Errorln,
			// this relies on implementation-specific details of the generic dlog Logger implementation, not good
			dlog.LevelFatal: glog.Fatalln,
			dlog.LevelPanic: glog.Errorln,
		},
	)
}
1209729
func NewLogger(prefix string, flags int, handler events.Handler) *log.Logger {
	return log.New(NewWriter(prefix, flags, handler), prefix, flags)
}
305690
func NewFileLogger(f string, o, mode, maxLines, maxRotate, bufsize int) (*FileLogger, error) {
	var file *os.File
	var err error

	switch mode {
	case APPEND:
		// open log file, append if it already exists
		file, err = os.OpenFile(f, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
	case TRUNC:
		// just truncate file and start logging
		file, err = os.OpenFile(f, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
	case BACKUP:
		// rotate every time a new logger is created
		file, err = openBackup(f, 0, maxRotate)
	case ROTATE:
		// "normal" rotation, when file reaches line limit
		file, err = openBackup(f, maxLines, maxRotate)
	default:
		return nil, fmt.Errorf("Invalid mode parameter: %d", mode)
	}
	if err != nil {
		return nil, fmt.Errorf("Error creating logger: %s", err)
	}

	return newFileLogger(file, o, mode, maxLines, maxRotate, bufsize), nil
}
35956
func NewBuildlogger(name string, conf *BuildloggerConfig, l LevelInfo) (Sender, error) {
	s, err := MakeBuildlogger(name, conf)
	if err != nil {
		return nil, err
	}

	return setup(s, name, l)
}
816203
func NewLogManager(path, name string) (*LogManager, error) {
	m := &LogManager{
		name:  name,
		nsMap: make(map[string]uint64),
	}

	l, err := commitlog.New(
		commitlog.WithPath(filepath.Join(path, fmt.Sprintf("%s-%s", offsetPrefixDir, name))),
		commitlog.WithMaxSegmentBytes(1024*1024*1024),
	)
	if err != nil {
		return nil, err
	}
	m.log = l

	err = m.buildMap()
	if err == io.EOF {
		return m, nil
	}

	return m, err
}
566269
func NewFileLog(cfg FileLogConfig) (*FileLog, error) {
	if err := cfg.CheckAndSetDefaults(); err != nil {
		return nil, trace.Wrap(err)
	}
	f := &FileLog{
		FileLogConfig: cfg,
		Entry: log.WithFields(log.Fields{
			trace.Component: teleport.ComponentAuditLog,
		}),
	}
	return f, nil
}
1127818
func New(info logger.Info) (logger.Logger, error) {
	var capval int64 = -1
	if capacity, ok := info.Config["max-size"]; ok {
		var err error
		capval, err = units.FromHumanSize(capacity)
		if err != nil {
			return nil, err
		}
		if capval <= 0 {
			return nil, fmt.Errorf("max-size must be a positive number")
		}
	}
	var maxFiles = 1
	if maxFileString, ok := info.Config["max-file"]; ok {
		var err error
		maxFiles, err = strconv.Atoi(maxFileString)
		if err != nil {
			return nil, err
		}
		if maxFiles < 1 {
			return nil, fmt.Errorf("max-file cannot be less than 1")
		}
	}

	var compress bool
	if compressString, ok := info.Config["compress"]; ok {
		var err error
		compress, err = strconv.ParseBool(compressString)
		if err != nil {
			return nil, err
		}
		if compress && (maxFiles == 1 || capval == -1) {
			return nil, fmt.Errorf("compress cannot be true when max-file is less than 2 or max-size is not set")
		}
	}

	attrs, err := info.ExtraAttributes(nil)
	if err != nil {
		return nil, err
	}

	// no default template. only use a tag if the user asked for it
	tag, err := loggerutils.ParseLogTag(info, "")
	if err != nil {
		return nil, err
	}
	if tag != "" {
		attrs["tag"] = tag
	}

	var extra []byte
	if len(attrs) > 0 {
		var err error
		extra, err = json.Marshal(attrs)
		if err != nil {
			return nil, err
		}
	}

	buf := bytes.NewBuffer(nil)
	marshalFunc := func(msg *logger.Message) ([]byte, error) {
		if err := marshalMessage(msg, extra, buf); err != nil {
			return nil, err
		}
		b := buf.Bytes()
		buf.Reset()
		return b, nil
	}

	writer, err := loggerutils.NewLogFile(info.LogPath, capval, maxFiles, compress, marshalFunc, decodeFunc, 0640, getTailReader)
	if err != nil {
		return nil, err
	}

	return &JSONFileLogger{
		writer:  writer,
		readers: make(map[*logger.LogWatcher]struct{}),
		tag:     tag,
	}, nil
}