An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 5.9% on proxy.golang.org
Top 0.9% dependent packages on proxy.golang.org
Top 1.1% dependent repos on proxy.golang.org

proxy.golang.org : github.com/powerman/structlog

Package structlog provides structured logger which looks friendly as plain text (more like handcrafted vertical-aligned log lines which doesn't feels like key/value pairs) but also really useful as JSON (each important value in log line became separate key/value pair). In short, with structlog you will have to write just this: and structlog will take care of the rest (output plain text or JSON, format plain text output to make it easy to read, include in output extra key/value pairs - both added by you before that call and calculated automatically like caller's details or stack trace). Well, not really. First you'll need to configure logger, to define what "easy to read" means in your case - but this has to be done just once, usually in main(), and then you'll get simple and powerful logging as promised above. It was designed to produce easy to read, vertically-aligned log lines while your project is small, and later, when your project will grow to use something like ELK Stack, switch by changing one option to produce easy to parse JSON log records. You can log key/value pairs without bothering about output format (plain text or JSON) and then fine-tune it plain text output by: Supported log levels: Err, Warn, Info and Debug. On import it calls stdlib's log.SetFlags(0) and by default will use stdlib's log.Print() to output log lines - this is to make sure structlog's output goes at same place as logging from other packages (which often use stdlib's log). For convenience you may have multiple loggers, and create new logger in such a way to inherit all settings from existing logger. These settings often include predefined key/value pairs to be automatically output in each logged line in addition to logger formatting setting. All loggers created using structlog.New() will inherit settings from logger in global variable structlog.DefaultLogger. So, usually you will configure structlog.DefaultLogger in your main(), to apply this configuration to each and every logger created in any other package of your application. Then you can do some extra setup on your logger (usually - just add some default key/value pair which should be output by each log call), and call log.New() method to get new logger which will inherit this extra setup. E.g. imagine HTTP middlewares: first will detect IP of connected client and store it in logger, second will check authentication and optionally add key/value pair with user ID - as result everything logged by your HTTP handler later using logger preconfigured by these middlewares will include remote IP and user ID in each log record - without needs to manually include it in each line where you log something. ★ Creating a new logger: ★ Passing logger inside context.Context: ★ Normal logging: ★ Logging useful with defer: ★ Delayed logging: ★ Configuring structlog.DefaultLogger in your main(): ★ Configuring current logger: ★ Handling log levels: ★ Passing this logger to 3rd-party packages which expects interface of stdlib's log.Logger: ★ Redirecting log output (useful to redirect to ioutil.Discard in tests):

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/powerman/structlog
License: MIT
Latest release: almost 4 years ago
First release: about 7 years ago
Namespace: github.com/powerman
Dependent packages: 27
Dependent repositories: 27
Stars: 18 on GitHub
Forks: 1 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 18 days ago

    Loading...
    Readme
    Loading...