{"id":22111241,"url":"https://github.com/tomakado/logo","last_synced_at":"2025-06-13T18:32:42.905Z","repository":{"id":53001439,"uuid":"345198236","full_name":"tomakado/logo","owner":"tomakado","description":"Experimental, opinionated and minimalistic logging library for Go.","archived":false,"fork":false,"pushed_at":"2021-04-10T09:38:35.000Z","size":54,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T10:29:48.253Z","etag":null,"topics":["golang","logging"],"latest_commit_sha":null,"homepage":"","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/tomakado.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":"2021-03-06T21:23:43.000Z","updated_at":"2023-02-11T16:39:16.000Z","dependencies_parsed_at":"2022-08-30T10:02:20.753Z","dependency_job_id":null,"html_url":"https://github.com/tomakado/logo","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomakado%2Flogo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomakado%2Flogo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomakado%2Flogo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomakado%2Flogo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomakado","download_url":"https://codeload.github.com/tomakado/logo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245209391,"owners_count":20578028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["golang","logging"],"created_at":"2024-12-01T10:37:40.611Z","updated_at":"2025-03-24T04:28:56.849Z","avatar_url":"https://github.com/tomakado.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# logo [![Go Reference](https://pkg.go.dev/badge/github.com/tomakado/logo.svg)](https://pkg.go.dev/github.com/tomakado/logo) [![Go Report Card](https://goreportcard.com/badge/github.com/tomakado/logo)](https://goreportcard.com/report/github.com/tomakado/logo) [![codecov](https://codecov.io/gh/tomakado/logo/branch/main/graph/badge.svg)](https://codecov.io/gh/tomakado/logo) [![Coverage Status](https://coveralls.io/repos/github/tomakado/logo/badge.svg?branch=main)](https://coveralls.io/github/tomakado/logo?branch=main) \n\nExperimental, opinionated and minimalistic logging library for Go.\n\nLibrary provides only two levels out of box \u0026mdash; *Verbose* and *Important.* Why so? It's mostly inspired by 🇷🇺 [this post](https://t.me/nikitonsky_pub/47) by [@tonsky](https://github.com/tonsky) and my personal experience.\n\nTLDR:\n- Only two logging levels: verbose and important.\n- *Important* level is for errors and business-critical stuff. *Verbose* level is for development purposes.\n- Stuff like \u0026ldquo;successfully connected to host ABC\u0026rdquo;, \u0026ldquo;binded port 8000\u0026rdquo;, etc. are not needed even at verbose level.\n- Libraries only use important level because debug related things are interesting only for library developers.\n\nHowever library allows to define custom levels. But before doing it, please think carefully.\n\n# Installation\n\n```bash\ngo get github.com/tomakado/logo\n```\n\n# Usage\n\nYou can use pre-instantiated logger and wrapper functions around\nit or create and customize your own.\n\n## Quick start\n\nFor quick start use package-level functions like this:\n\n```golang\npackage main\n\nimport (\n    \"context\"\n\n    \"github.com/tomakado/logo/log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    log.Verbose(ctx, \"hello!\")\n    log.Important(ctx, \"hello, it's important\")\n    log.VerboseX(ctx, \"hello with extra!\", log.Extra{\"foo\": \"bar\"})\n    log.Verbosef(ctx, \"hello, %s\", \"Jon Snow\")\n\n    log.Write(ctx, log.LevelImportant, \"hello, it's me\", Extra{\"a\": 42})\n    log.Writef(ctx, log.LevelVerbose, \"My name is %s, I'm %d y.o.\", \"Ildar\", 23)\n}\n```\n\nFor fine-tuned logging create custom logger with [`NewLogger`](https://pkg.go.dev/github.com/tomakado/logo/log#NewLogger) function:\n\n```golang\npackage main\n\nimport (\n    \"context\"\n    \"os\"\n\n    \"github.com/tomakado/logo/log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    logger := log.NewLogger(log.LevelImportant, os.Stderr, log.SimpleTextFormatter)\n\n    logger.Verbose(ctx, \"hello!\") // will not be sent to output\n    logger.Important(ctx, \"this is really important\")\n}\n```\n\n## Logging levels\n\nlogo's logging level is a pair of numeric value and string representation of level and can be defined with [`NewLevel`](https://pkg.go.dev/github.com/tomakado/logo/log#NewLevel) function:\n\n```golang\nvar (\n    LevelVerbose   Level = NewLevel(10, \"VERBOSE\")\n    LevelImportant Level = NewLevel(20, \"IMPORTANT\")\n)\n```\n\n## Message format\n\n[`NewLogger`](https://pkg.go.dev/github.com/tomakado/logo/log#NewLogger) accepts [`Formatter`](https://pkg.go.dev/github.com/tomakado/logo/log#Formatter) as third argument to create logger. There are two formatter types out of box: [`JSONFormatter`](https://pkg.go.dev/github.com/tomakado/logo/log#JSONFormatter) and [`TemplateFormatter`](https://pkg.go.dev/github.com/tomakado/logo/log#TemplateFormatter) and two pre-instantiated template formatters: [`SimpleTextFormatter`](https://pkg.go.dev/github.com/tomakado/logo/log#SimpleTextFormatter) and [`TableTextFormatter`](https://pkg.go.dev/github.com/tomakado/logo/log#TableTextFormatter).\n\n[`TemplateFormatter`](https://pkg.go.dev/github.com/tomakado/logo/log#TemplatesFormatter) uses template engine from Go's standard library to format messages:\n\n```golang\ntmpl, err := template.New(\"tmpl_fmt_example\").\n    Parse(\"ts={{.Time}} level={{.Level}} msg=\\\"{{.Message}}\\\" extra={{.Extra}}\")\nif err != nil {\n    panic(err)\n}\n\nformatter := log.NewTemplateFormatter(tmpl)\nlogger := log.NewLogger(log.LevelVerbose, os.Stdout, formatter)\n\nlogger.Verbose(context.Background(), \"hello\")\n```\n\n## Hooks\n\nHooks are functions called before or after log message has been sent to output. Pre-hooks are useful when you need to extend the context of event. Post-hooks can be used to send events to external services (e.g. Sentry), collect metrics, etc.\n\n```golang\npackage main\n\nimport (\n    \"context\"\n\n    \"github.com/tomakado/logo/hooks\"\n    \"github.com/tomakado/logo/log\"\n)\n\nfunc main() {\n    ...\n\n    log.PreHook(func(ctx context.Context, e *log.Event) {\n        e.Extra[\"request_id\"] = uuid.New()\n    })\n\n    log.PostHook(\n        hooks.FilteredHook(\n            func(ctx context.Context, e *log.Event) {\n                // Send event to external log storage here\n            },\n            hooks.LevelBoundsFilter(log.LevelVerbose, log.LevelImportant),\n        ),\n    )\n\n    log.PostHook(hooks.ExitOnImportant) // os.Exit(1) if event level is \u003e= log.LevelImportant\n\n    ...\n}\n```\n\n## Contributing\n\nIf you want to contribute to logo \u0026mdash; you're welcome! Feel free to send your issues and PRs.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomakado%2Flogo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomakado%2Flogo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomakado%2Flogo/lists"}