// WithTSMFilenameFormatter sets a function on the underlying tsm1.Engine to specify
// how TSM files are named.
335654
func WithTSMFilenameFormatter(fn tsm1.FormatFileNameFunc) Option {
	return func(e *Engine) {
		e.engine.WithFormatFileNameFunc(fn)
	}
}
213598
func UnixFormatter(p Priority, hostname, tag, content string) string {
	timestamp := time.Now().Format(time.Stamp)
	msg := fmt.Sprintf("<%d>%s %s[%d]: %s",
		p, timestamp, tag, os.Getpid(), content)
	return msg
}
507935
func (t *Template) GetAWSSSMDocumentWithName(name string) (*resources.AWSSSMDocument, error) {
	if untyped, ok := t.Resources[name]; ok {
		switch resource := untyped.(type) {
		case *resources.AWSSSMDocument:
			return resource, nil
		}
	}
	return nil, fmt.Errorf("resource %q of type AWSSSMDocument not found", name)
}
406719
func (t *templateHandler) NewTextTemplate() tpl.TemplateParseFinder {
	t.mu.Lock()
	defer t.mu.Unlock()

	tt := &textTemplate{t: texttemplate.New("")}
	t.extTextTemplates = append(t.extTextTemplates, tt)

	return struct {
		tpl.TemplateParser
		tpl.TemplateLookup
		tpl.TemplateLookupVariant
	}{
		tt,
		tt,
		new(nopLookupVariant),
	}

}
920625
func (format *CollectdToInflux10) ApplyFormatter(msg *core.Message) error {
	contentData := format.GetAppliedContent(msg)

	collectdData, err := parseCollectdPacket(contentData)
	if err != nil {
		format.Logger.Error("Collectd parser error: ", err)
		return err
	}

	// Manually convert to line protocol
	influxData := tio.NewByteStream(len(contentData))
	timestamp := int64(collectdData.Time * 1000)
	fixedPart := fmt.Sprintf(
		`%s,plugin_instance=%s,type=%s,type_instance=%s,host=%s`,
		format.escapeTag(collectdData.Plugin),
		format.escapeTag(collectdData.PluginInstance),
		format.escapeTag(collectdData.PluginType),
		format.escapeTag(collectdData.TypeInstance),
		format.escapeTag(collectdData.Host))

	setSize := tmath.Min3I(len(collectdData.Dstypes), len(collectdData.Dsnames), len(collectdData.Values))
	for i := 0; i < setSize; i++ {
		fmt.Fprintf(&influxData,
			`%s,dstype=%s,dsname=%s value=%f %d\n`,
			fixedPart,
			format.escapeTag(collectdData.Dstypes[i]),
			format.escapeTag(collectdData.Dsnames[i]),
			collectdData.Values[i],
			timestamp)
	}

	format.SetAppliedContent(msg, influxData.Bytes())
	return nil
}
230710
func StatsFilename(tsmPath string) string {
	if strings.HasSuffix(tsmPath, "."+TmpTSMFileExtension) {
		tsmPath = strings.TrimSuffix(tsmPath, "."+TmpTSMFileExtension)
	}
	if strings.HasSuffix(tsmPath, "."+TSMFileExtension) {
		tsmPath = strings.TrimSuffix(tsmPath, "."+TSMFileExtension)
	}
	return tsmPath + "." + TSSFileExtension
}
152737
func (format *Identifier) ApplyFormatter(msg *core.Message) error {
	format.SetAppliedContent(msg, format.hash(msg))
	return nil
}
1051277
func (format *StreamRevert) ApplyFormatter(msg *core.Message) error {
	msg.SetStreamID(msg.GetPrevStreamID())
	return nil
}
500701
func WithMap(template string, m map[string]string) (string, error) {
	format := func(key string, w io.Writer) error {
		value, ok := m[key]
		if !ok {
			return ErrKeyNotFound
		}
		_, err := w.Write([]byte(value))
		return err
	}
	return WithFunc(template, format)
}
1365380
func FloatValueFormatterWithFormat(v interface{}, floatFormat string) string {
	if typed, isTyped := v.(int); isTyped {
		return fmt.Sprintf(floatFormat, float64(typed))
	}
	if typed, isTyped := v.(int64); isTyped {
		return fmt.Sprintf(floatFormat, float64(typed))
	}
	if typed, isTyped := v.(float32); isTyped {
		return fmt.Sprintf(floatFormat, typed)
	}
	if typed, isTyped := v.(float64); isTyped {
		return fmt.Sprintf(floatFormat, typed)
	}
	return ""
}
1142564
func (b *BatchBuilder) AddStmtWithPrefix(prefix string, stmt string, names []string) *BatchBuilder {
	b.stmts = append(b.stmts, stmt)
	for _, name := range names {
		if prefix != "" {
			name = fmt.Sprint(prefix, ".", name)
		}
		b.names = append(b.names, name)
	}
	return b
}
1271786
func StructToForm(ctx Context, m interface{}, topName string, fieldNameFormatter FieldNameFormatter) {
	vc := reflect.ValueOf(m)
	tc := reflect.TypeOf(m)

	switch tc.Kind() {
	case reflect.Struct:
	case reflect.Ptr:
		vc = vc.Elem()
		tc = tc.Elem()
	}
	l := tc.NumField()
	f := ctx.Request().Form()
	if fieldNameFormatter == nil {
		fieldNameFormatter = DefaultFieldNameFormatter
	}

	for i := 0; i < l; i++ {
		fVal := vc.Field(i)
		fTyp := tc.Field(i)

		fName := fieldNameFormatter(topName, fTyp.Name)
		if !fVal.CanInterface() || len(fName) == 0 {
			continue
		}
		switch fTyp.Type.String() {
		case "time.Time":
			if t, y := fVal.Interface().(time.Time); y {
				dateformat := tagfast.Value(tc, fTyp, `form_format`)
				if len(dateformat) > 0 {
					f.Add(fName, t.Format(dateformat))
				} else {
					f.Add(fName, t.Format(`2006-01-02 15:04:05`))
				}
			}
		case "struct":
			StructToForm(ctx, fVal.Interface(), fName, fieldNameFormatter)
		default:
			f.Add(fName, fmt.Sprint(fVal.Interface()))
		}
	}
}
621567
func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error {
	val := f.Value
	if fileEnvVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok {
		if err := val.Set(fileEnvVal); err != nil {
			return fmt.Errorf("could not parse %s as value for flag %s: %s", fileEnvVal, f.Name, err)
		}
	}

	eachName(f.Name, func(name string) {
		set.Var(f.Value, name, f.Usage)
	})

	return nil
}
897803
func (c *Command) MarkFlagFilename(name string, extensions ...string) error {
	return MarkFlagFilename(c.Flags(), name, extensions...)
}
1196173
func prepCorefileFormat(s string, indentation int) string {
	var r []string
	if s == "" {
		return ""
	}
	for _, line := range strings.Split(s, "\n") {
		indented := strings.Repeat(" ", indentation) + line
		r = append(r, indented)
	}
	corefile := strings.Join(r, "\n")
	return "\n" + strings.Replace(corefile, "\t", "   ", -1)
}
882945
func createFormatter(name string, kind string) (Formatter, error) {
	if kind == FormatEnv {
		kind = logxiFormat
	}
	if kind == "" {
		kind = FormatText
	}

	fn := formatterCreators[kind]
	if fn == nil {
		fn = formatterCreators[FormatText]
	}

	formatter, err := fn(name, kind)
	if err != nil {
		return nil, err
	}
	// custom formatter may have not returned a formatter
	if formatter == nil {
		formatter, err = formatFactory(name, FormatText)
	}
	return formatter, err
}
615017
func NewTextFormatter(name string) *TextFormatter {
	timeLabel := KeyMap.Time + AssignmentChar
	levelLabel := Separator + KeyMap.Level + AssignmentChar
	messageLabel := Separator + KeyMap.Message + AssignmentChar
	nameLabel := Separator + KeyMap.Name + AssignmentChar
	pidLabel := Separator + KeyMap.PID + AssignmentChar

	var buildKV = func(level string) string {
		buf := pool.Get()
		defer pool.Put(buf)

		buf.WriteString(pidLabel)
		buf.WriteString(pidStr)

		//buf.WriteString(Separator)
		buf.WriteString(nameLabel)
		buf.WriteString(name)

		//buf.WriteString(Separator)
		buf.WriteString(levelLabel)
		buf.WriteString(level)

		//buf.WriteString(Separator)
		buf.WriteString(messageLabel)

		return buf.String()
	}
	itoaLevelMap := map[int]string{
		LevelDebug: buildKV(LevelMap[LevelDebug]),
		LevelWarn:  buildKV(LevelMap[LevelWarn]),
		LevelInfo:  buildKV(LevelMap[LevelInfo]),
		LevelError: buildKV(LevelMap[LevelError]),
		LevelFatal: buildKV(LevelMap[LevelFatal]),
	}
	return &TextFormatter{itoaLevelMap: itoaLevelMap, name: name, timeLabel: timeLabel}
}