{"id":26299213,"url":"https://github.com/trackit/jsonlog","last_synced_at":"2025-03-15T06:47:49.282Z","repository":{"id":48352001,"uuid":"105931643","full_name":"trackit/jsonlog","owner":"trackit","description":"A structured logger for Go","archived":false,"fork":false,"pushed_at":"2021-07-30T14:30:51.000Z","size":11,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2023-08-12T04:13:32.872Z","etag":null,"topics":[],"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/trackit.png","metadata":{"files":{"readme":"README.adoc","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-05T19:29:50.000Z","updated_at":"2021-07-30T14:18:55.000Z","dependencies_parsed_at":"2022-09-07T19:10:12.127Z","dependency_job_id":null,"html_url":"https://github.com/trackit/jsonlog","commit_stats":null,"previous_names":[],"tags_count":2,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trackit%2Fjsonlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trackit%2Fjsonlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trackit%2Fjsonlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trackit%2Fjsonlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trackit","download_url":"https://codeload.github.com/trackit/jsonlog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243695496,"owners_count":20332626,"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":[],"created_at":"2025-03-15T06:47:48.658Z","updated_at":"2025-03-15T06:47:49.276Z","avatar_url":"https://github.com/trackit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"jsonlog\n=======\nVictor Schubert \u003cvictor@trackit.io\u003e\nv1.0, 2017-10-05\n\n_jsonlog_ is a simple Go logger. It produces structured logs using JSON and can\nalso output arbitrary data taken as an argument and from a `context.Context`.\n\n== Usage\n\n=== Logging\n\nThe module provides a default logger which logs on the standard output.\n\n[source,go]\n----\npackage main\n\nimport \"github.com/trackit/jsonlog\"\n\nfunc main() {\n\tjsonlog.DefaultLogger.Info(\"Info log message\", nil)\n\tjsonlog.DefaultLogger.Warning(\"Warning with data\", map[string]int{ \"foobar\": 42 })\n}\n----\n\nThis code produces the following output (the JSON objects were prettified, the\nlibrary outputs each object on a single line and without unnecessary spaces):\n\n[source,json]\n----\n{\n  \"message\": \"Info log message\",\n  \"level\": \"info\",\n  \"time\": \"2017-10-05T21:07:58.115210089+02:00\"\n}\n{\n  \"message\": \"Warning with data\",\n  \"level\": \"warning\",\n  \"time\": \"2017-10-05T21:07:58.115320884+02:00\",\n  \"data\": {\n    \"foobar\": 42\n  }\n}\n----\n\n=== Choosing the log level\n\nThe logger has four log levels: debug, info, warning and error. Each message\nhas a `\"level\"` field to indicate the message's level.\n\n[source,go]\n----\npackage main\n\nimport \"github.com/trackit/jsonlog\"\n\nfunc main() {\n\tlogger := jsonlog.DefaultLogger.WithLogLevel(jsonlog.LogLevelDebug)\n\tlogger.Debug(\"Debug message. Only prints with adequate log level.\", nil)\n}\n----\n\n=== Using values from a context\n\nThe Go standard library provides the `context` module to propagate\ncancellation, enforce timeouts and hold data about the current context.\n_jsonlog_ can make use of those values.\n\n[source,go]\n----\npackage main\n\nimport (\n\t\"context\"\n\t\"math/rand\"\n\n\t\"github.com/trackit/jsonlog\"\n)\n\nconst (\n\trunId = iota\n)\n\nfunc main() {\n\tctx := context.WithValue(context.Background(), runId, rand.Int63())\n\tlogger := jsonlog.DefaultLogger.WithContext(ctx).WithContextKey(runId, \"runId\")\n\tlogger.Info(\"Log with context\", nil)\n}\n----\n\nA `Logger` with a `Context` and registered context keys will include the\ncontext values in each message; the previous code would produce the following\nlog: (the JSON object was prettified)\n\n[source,go]\n----\n{\n  \"message\": \"Log with context\",\n  \"level\": \"info\",\n  \"time\": \"2017-10-05T21:18:49.973938562+02:00\",\n  \"context\": {\n    \"runId\": 5577006791947779410\n  }\n}\n----\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrackit%2Fjsonlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrackit%2Fjsonlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrackit%2Fjsonlog/lists"}