Debian Codegraph @

flagset.go

raw symbols SCIP
1 // Copyright (c) 2012-2016 Eli Janssen
2 // Use of this source code is governed by an MIT-style
3 // license that can be found in the LICENSE file.
4
5 package mlog
6
7 import (
8 "sort"
9 "strings"
10 )
11
12 const (
13 // Bits or'ed together to control what's printed.
14
15 // Ltimestamp specifies to log the date+time stamp
16 Ltimestamp FlagSet = 1 << iota
17 // Ltai64n specifies to use tia64n timestamps
18 // overrides Ltimestamp.
19 Ltai64n
20 // Llevel specifies to log message level.
21 Llevel
22 // Llongfile specifies to log file path and line number: /a/b/c/d.go:23
23 Llongfile
24 // Lshortfile specifies to log file name and line number: d.go:23.
25 // overrides Llongfile.
26 Lshortfile
27 // Lsort specifies to sort Map key value pairs in output.
28 Lsort
29 // Ldebug specifies to enable debug level logging.
30 Ldebug
31 // Lstd is the standard log format if none is specified.
32 Lstd = Ltimestamp | Llevel | Lsort
33 )
34
35 var flagNames = map[FlagSet]string{
36 Ltimestamp: "Ltimestamp",
37 Ltai64n: "Ltai64n",
38 Llevel: "Llevel",
39 Llongfile: "Llongfile",
40 Lshortfile: "Lshortfile",
41 Lsort: "Lsort",
42 Ldebug: "Ldebug",
43 }
44
45 // FlagSet defines the output formatting flags (bitfield) type, which define
46 // certainly fields to appear in the output.
47 type FlagSet uint64
48
49 // Has returns true if the FlagSet argument is in the set of flags (binary &)
50 func (f *FlagSet) Has(p FlagSet) bool {
51 return *f&p != 0
52 }
53
54 // GoString fulfills the GoStringer interface, defining the format used for
55 // the %#v format string.
56 func (f FlagSet) GoString() string {
57 s := make([]byte, 0, len(flagNames))
58 var p uint64
59 for p = 256; p > 0; p >>= 1 {
60 if f&FlagSet(p) != 0 {
61 s = append(s, '1')
62 } else {
63 s = append(s, '0')
64 }
65 }
66 return string(s)
67 }
68
69 // String fulfills the Stringer interface, defining the format used for
70 // the %s format string.
71 func (f FlagSet) String() string {
72 flags := make([]string, 0, len(flagNames))
73 for k, v := range flagNames {
74 if f&k != 0 {
75 flags = append(flags, v)
76 }
77 }
78 sort.Strings(flags)
79 return "FlagSet(" + strings.Join(flags, "|") + ")"
80 }