A simple, yet effective and clean logger
refactor: Move Envelope interface. fix: Deadlock when logging traces. fix: Suppress hook execution, when logging traces. feat: Formatter initialization and configuration. feat: Exit hook on FATAL logs. chore: Prepare tokenizer for log configuration parsing. fix: Early formatter/logger init. feat: Supply version and build information. |
||
|---|---|---|
| example | ||
| formatter/json | ||
| lex | ||
| .gitignore | ||
| doc.go | ||
| envelope.go | ||
| formatter.go | ||
| formatter_plain.go | ||
| go.mod | ||
| go.sum | ||
| grpc.go | ||
| level.go | ||
| logger.go | ||
| README.md | ||
| tag.go | ||
| version.go | ||
log
Package log provides an easy to use, yet highly configurable Logger.
Usage
In its simplest form, a log message can be created by just:
import "udico.de/util/log"
log.INFO.Msg("Hello log!")
This will use the default Logger without further configuration and produce something like this to stdout:
20251121-113125.038747 INFO: Hello log!
If stdout targets an interactive terminal, the output will be colored by the default formatter. More on Formatters below.
Customizing a Logger
Of course, you can customize a Logger
log.DefaultLogger.SetLevel(log.TRACE)
// .SetFormatter(...)
// .SetAutotrace(...)
package mypackage
import "udico.de/util/log"
var logger = log.Logger("mylog").SetLevel(log.DEBUG)
Autotrace
Log levels
udilog provides the following log levels:
| Level | Name (Short) | Description |
|---|---|---|
| 0 | SILENT (SLT) | No log at all. not even panics. We just don't care about the end of the world. |
| 1 | PANIC (PNC) | Events which cannot be handled gracefully. Program execution will terminate. |
| 2 | FATAL (FTL) | Indicates a situation which requires user interaction to resolve. |
| 3 | ERROR (ERR) | Error conditions which may result in malfunction. |
| 4 | WARN (WRN) | Signifies potential issues that may lead to errors or unexpected behavior in the future if not addressed. |
| 5 | NOTICE (NOT) | Notice logs are normal but significant information. |
| 6 | INFO (INF) | Indicates normal, informational messages. |
| 7 | DEBUG (DBG) | Is intended for logging detailed information for debugging purposes. |
| 8 | TRACE (TRC) | Is the most detailed level of log output. Might spam your logs. |
Note: logging a PANIC will also issue a panic and thereby terminate the program.
Configuration
stub
Formatters
stub
Targets
stub
gRPC
You can also use a Logger for gRPC logging.