Documentation ¶
Overview ¶
Example ¶
_ = os.Setenv("DEBUG", "example:*") // OR // _ = os.Setenv("KEMBA", "example:*") k := New("example:tag") type myType struct { a, b int } var x = []myType{{1, 2}, {3, 4}} k.Printf("%#v", x) // Output to os.Stderr // example:tag []main.myType{main.myType{a:1, b:2}, main.myType{a:3, b:4}} +0s // Artificial delay to demonstrate the time tagging time.Sleep(250 * time.Millisecond) k.Printf("%# v", x) k.Println(x) // Artificial delay to demonstrate the time tagging time.Sleep(100 * time.Millisecond) k.Log(x) // All result in the same output to os.Stderr // example:tag []main.myType{ +XXs // example:tag {a:1, b:2}, // example:tag {a:3, b:4}, // example:tag } // Create a new extended logger with a new tag k1 := k.Extend("1") k1.Println("a string", 12, true) // Output to os.Stderr // example:tag:1 a string +0s // example:tag:1 int(12) // example:tag:1 bool(true) _ = os.Setenv("DEBUG", "")
Output: example:tag []kemba.myType{kemba.myType{a:1, b:2}, kemba.myType{a:3, b:4}} +0s example:tag []kemba.myType{ +250ms example:tag {a:1, b:2}, example:tag {a:3, b:4}, example:tag } example:tag []kemba.myType{ +0s example:tag {a:1, b:2}, example:tag {a:3, b:4}, example:tag } example:tag []kemba.myType{ +105ms example:tag {a:1, b:2}, example:tag {a:3, b:4}, example:tag } example:tag:1 a string +0s example:tag:1 int(12) example:tag:1 bool(true)
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Kemba ¶
type Kemba struct {
// contains filtered or unexported fields
}
Kemba is a container struct for the Kemba logger. It used to manage the state of the logger. Currently all properties are not exported.
func New ¶
New Returns a Kemba logging instance. It will determine if the logger should bypass logging actions or be activated.
func (*Kemba) Extend ¶ added in v0.3.0
Extend returns a new Kemba logger instance that has appended the provided tag to the original logger.
New logger instance will have original `tag` value delimited with a `:` and appended with the new extended `tag` input.
Example:
k := New("test:original) k.Log("test") ke := k.Extend("plugin") ke.Log("test extended")
Output:
test:original test test:original:plugin test extended
func (*Kemba) Log ¶
func (k *Kemba) Log(v ...interface{})
Log is an alias to Println
Example ¶
_ = os.Setenv("DEBUG", "test:*") k := New("test:kemba") k.Printf("%s", "Hello") type myType struct { a, b int } var x = []myType{{1, 2}, {3, 4}, {5, 6}} k.Log(x) _ = os.Setenv("DEBUG", "")
Output: test:kemba Hello +0s test:kemba []kemba.myType{ +0s test:kemba {a:1, b:2}, test:kemba {a:3, b:4}, test:kemba {a:5, b:6}, test:kemba }
func (*Kemba) Printf ¶
Printf is a convenience wrapper that will apply pretty.Formatter to the passed in variables.
Calling Printf(f, x, y) is equivalent to fmt.Printf(f, pretty.Formatter(x), pretty.Formatter(y)).
Example ¶
_ = os.Setenv("DEBUG", "test:*") k := New("test:kemba") k.Printf("%s", "Hello") k1 := k.Extend("1") k1.Printf("%s", "Hello 1") k2 := k.Extend("2") k2.Printf("%s", "Hello 2") k3 := k.Extend("3") k3.Printf("%s", "Hello 3") s := []string{"test", "again", "third"} k2.Printf("%# v", s) m := map[string]int{ "test": 1, "again": 1337, "third": 732, } k1.Printf("%# v", m) type myType struct { a int b int } var x = []myType{{1, 2}, {3, 4}, {5, 6}} k3.Printf("%# v", x) k2.Printf("%#v", x) k.Printf("%#v %#v %#v %#v %#v %#v", m, s, m, s, m, s) _ = os.Setenv("DEBUG", "")
Output: test:kemba Hello +0s test:kemba:1 Hello 1 +0s test:kemba:2 Hello 2 +0s test:kemba:3 Hello 3 +0s test:kemba:2 []string{"test", "again", "third"} +0s test:kemba:1 map[string]int{"again":1337, "third":732, "test":1} +0s test:kemba:3 []kemba.myType{ +0s test:kemba:3 {a:1, b:2}, test:kemba:3 {a:3, b:4}, test:kemba:3 {a:5, b:6}, test:kemba:3 } test:kemba:2 []kemba.myType{kemba.myType{a:1, b:2}, kemba.myType{a:3, b:4}, kemba.myType{a:5, b:6}} +0s test:kemba map[string]int{"again":1337, "test":1, "third":732} []string{"test", "again", "third"} map[string]int{"again":1337, "test":1, "third":732} []string{"test", "again", "third"} map[string]int{"again":1337, "test":1, "third":732} []string{"test", "again", "third"} +0s
Example (Compact) ¶
_ = os.Setenv("DEBUG", "test:*") k := New("test:kemba") type myType struct { a int b int } var x = []myType{{1, 2}, {3, 4}, {5, 6}} // NOTE: The "%#v" operand for the Printf format. k.Printf("%#v", x) _ = os.Setenv("DEBUG", "")
Output: test:kemba []kemba.myType{kemba.myType{a:1, b:2}, kemba.myType{a:3, b:4}, kemba.myType{a:5, b:6}} +0s
Example (Expanded) ¶
_ = os.Setenv("DEBUG", "test:*") k := New("test:kemba") k.Printf("%s", "Hello") type myType struct { a int b int } var x = []myType{{1, 2}, {3, 4}, {5, 6}} // NOTE: The "%# v" operand for the Printf format. k.Printf("%# v", x) _ = os.Setenv("DEBUG", "")
Output: test:kemba Hello +0s test:kemba []kemba.myType{ +0s test:kemba {a:1, b:2}, test:kemba {a:3, b:4}, test:kemba {a:5, b:6}, test:kemba }
func (*Kemba) Println ¶
func (k *Kemba) Println(v ...interface{})
Println is a convenience wrapper that will apply pretty.Formatter to the passed in variables.
Calling Println(x, y) is equivalent to fmt.Println(pretty.Formatter(x), pretty.Formatter(y)), but each operand is formatted with "%# v".
Example ¶
_ = os.Setenv("DEBUG", "test:*") k := New("test:kemba") k.Printf("%s", "Hello") type myType struct { a int b int } var x = []myType{{1, 2}, {3, 4}, {5, 6}} k.Println(x) _ = os.Setenv("DEBUG", "")
Output: test:kemba Hello +0s test:kemba []kemba.myType{ +0s test:kemba {a:1, b:2}, test:kemba {a:3, b:4}, test:kemba {a:5, b:6}, test:kemba }