File: format.go

package info (click to toggle)
golang-github-d2r2-go-logger 0.0~git20210606.60e9d12-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 100 kB
  • sloc: makefile: 2
file content (31 lines) | stat: -rw-r--r-- 621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package logger

import "os"

type LevelLength int

const (
	LevelShort LevelLength = iota
	LevelLong
)

type FormatOptions struct {
	TimeFormat    string
	PackageLength int
	LevelLength   LevelLength
}

func FormatMessage(options FormatOptions, level LogLevel, packageName, msg string, colored bool) string {
	appName := os.Args[0]
	out := metaFmtStr(colored, level, options, appName,
		packageName, msg, "%[1]s [%[3]s] %[4]s  %[5]s")
	return out
}

func (options FormatOptions) GetLevelStr(level LogLevel) string {
	if options.LevelLength == LevelLong {
		return level.LongStr()
	} else {
		return level.ShortStr()
	}
}