{"id":13413300,"url":"https://github.com/teris-io/log","last_synced_at":"2026-01-20T12:02:17.821Z","repository":{"id":57496858,"uuid":"108679849","full_name":"teris-io/log","owner":"teris-io","description":"Structured log interface","archived":false,"fork":false,"pushed_at":"2017-12-04T18:53:45.000Z","size":21,"stargazers_count":26,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T04:02:01.117Z","etag":null,"topics":["logger-interface","logging","logging-facade","structured-logging"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teris-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-28T19:57:55.000Z","updated_at":"2024-01-03T14:15:17.000Z","dependencies_parsed_at":"2022-09-03T02:30:48.696Z","dependency_job_id":null,"html_url":"https://github.com/teris-io/log","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/teris-io/log","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teris-io%2Flog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teris-io%2Flog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teris-io%2Flog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teris-io%2Flog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teris-io","download_url":"https://codeload.github.com/teris-io/log/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teris-io%2Flog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28603303,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T12:01:53.233Z","status":"ssl_error","status_checked_at":"2026-01-20T12:01:46.545Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logger-interface","logging","logging-facade","structured-logging"],"created_at":"2024-07-30T20:01:37.165Z","updated_at":"2026-01-20T12:02:17.806Z","avatar_url":"https://github.com/teris-io.png","language":"Go","readme":"[![Build status][buildimage]][build] [![Coverage][codecovimage]][codecov] [![GoReportCard][cardimage]][card] [![API documentation][docsimage]][docs]\n\n# Structured log interface\n\nPackage `log` provides the separation of the logging interface from its \nimplementation and decouples the logger backend from your application. It defines\na simple, lightweight and comprehensive `Logger` and `Factory` interfaces which \ncan be used through your applications without any knowledge of the particular\nimplemeting backend and can be configured at the application wiring point to\nbind a particular backend, such as Go's standard logger, `apex/log`, `logrus`, \nwith ease.\n\nTo complement the facade, the package `github.com/teris-io/log/std` provides an \nimplementation using the standard Go logger. The default log formatter for\nthis implementation uses colour coding for log levels and logs the date\nleaving out the month and the year on the timestamp. However, the formatter\nis fully configurable.\n\nSimilarly, the package `github.com/teris-io/log/apex` provides and implementation \nusing the `apex/log` logger backend.\n\n\n## Interface details\n\nThe `Logger` interface defines a facade for a structured leveled log: \n\n```go\ntype Logger interface {\n\tLevel(lvl LogLevel) Logger\n\tField(k string, v interface{}) Logger\n\tFields(data map[string]interface{}) Logger\n\tError(err error) Logger\n\tLog(msg string) Tracer\n\tLogf(format string, v ...interface{}) Tracer\n}\n```\n\nThe `Factory` defines a facade for the creation of logger instances and setting the\nlog output threshold for newly created instances:\n\n```go\ntype Factory interface {\n\tNew() Logger\n\tThreshold(min LogLevel)\n}\n```\n\nThe package further defines three log levels differentiating between the (normally hidden) \n`Debug`, (default) `Info` and (erroneous) `Error`.\n\n\n## Usage\n\nThe log can be used both statically by binding a particular logger factory:\n\n```go\nfunc init() {\n\tstd.Use(os.Stderr, log.InfoLevel, std.DefaultFmtFun)\n}\n\n// elsewhere\t\nlogger := log.Level(log.InfoLevel).Field(\"key\", \"value\")\nlogger.Log(\"message\")\n```\n\nand dynamically by always going via a factory:\n\n```go\nfactory := std.NewFactory(os.Stderr, log.InfoLevel, std.DefaultFmtFun)\nlogger := factory.Level(log.InfoLevel).Field(\"key\", \"value\")\nlogger.Log(\"message\")\n```\n\nBy default a NoOp (no-operation) implementation is bound to the static factory.\n\n## Tracing\n\nTo simplify debugging with execution time tracing, the `Log` and `Logf` methods\nreturn a tracer that can be used to measure and log the execution time:\n\n```go\nlogger := log.Level(log.DebugLevel).Field(\"key\", \"value\")\n\ndefer logger.Log(\"start\").Trace()\n// code to trace the execution time of\n```\n\nThe above code snippet would output two log entries (provided the threshold permits)\nthe selected `Debug` level (her for the default formatter of the `std` logger):\n\n\t08 16:31:42.023798 DBG start {key: value}\n\t08 16:31:45.127619 DBG traced {duration: 3.103725832}, {key: value}\n\n### License and copyright\n\n\tCopyright (c) 2017. Oleg Sklyar and teris.io. MIT license applies. All rights reserved.\n\n\n[build]: https://travis-ci.org/teris-io/log\n[buildimage]: https://travis-ci.org/teris-io/log.svg?branch=master\n\n[codecov]: https://codecov.io/github/teris-io/log?branch=master\n[codecovimage]: https://codecov.io/github/teris-io/log/coverage.svg?branch=master\n\n[card]: http://goreportcard.com/report/teris-io/log\n[cardimage]: https://goreportcard.com/badge/github.com/teris-io/log\n\n[docs]: https://godoc.org/github.com/teris-io/log\n[docsimage]: http://img.shields.io/badge/godoc-reference-blue.svg?style=flat\n","funding_links":[],"categories":["Logging","Logging 日志库","Relational Databases","日志","日志记录","\u003cspan id=\"日志-logging\"\u003e日志 Logging\u003c/span\u003e"],"sub_categories":["Advanced Console UIs","Search and Analytic Databases","SQL 查询语句构建库","交流","检索及分析资料库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteris-io%2Flog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteris-io%2Flog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteris-io%2Flog/lists"}