Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EnvSourceFunc ¶
type EnvSourceFunc func() string
EnvSourceFunc is a type of function that returns a DEBUG value. Use it with UseEnvSource option if you don't want to use standard UseEnvVar option.
type Logger ¶
type Logger interface {
// Print writes a message via the fmt.Sprint
Print(v ...interface{})
// Print writes a message via the fmt.Sprintf
Printf(format string, v ...interface{})
// Print writes a message via the fmt.Sprintln
Println(v ...interface{})
// Returns logger name
Name() string
// Output returns the underlying writer of the logger
Output() io.Writer
// Fork creates a new Logger with the same options but with a new name
Fork(name string, options ...Option) Logger
}
Logger is a minimal logger interface.
func NewLogger ¶
NewLogger creates a new named logger with the given options. If no options are provided, the following defaults are used: WithOutput(os.Stdout) and UseEnvVar("DEBUG").
Example ¶
package main
import (
"os"
"github.com/davidmz/debug-log"
)
func main() {
_ = os.Setenv("DEBUG", "test")
logger := debug.NewLogger("test", debug.WithoutTime())
logger.Println("log line")
}
Output: [test] log line
Example (UseEnvString) ¶
package main
import (
"github.com/davidmz/debug-log"
)
func main() {
logger := debug.NewLogger("test", debug.WithoutTime(), debug.UseEnvString("test"))
logger.Println("log line")
}
Output: [test] log line
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option allows to configure logger. Use them in NewLogger as arguments.
func UseEnvSource ¶
func UseEnvSource(src EnvSourceFunc) Option
UseEnvSource allows to use custom source of DEBUG value. Use UseEnvVar to obtain DEBUG from the environment variable.
func UseEnvString ¶ added in v1.2.0
UseEnvString sets the constant string as the DEBUG value.
func WithOutput ¶
WithOutput sets the output writer for the logger.
func WithPrefix ¶ added in v1.3.0
WithPrefix sets the prefix for the logger.