{"id":21658121,"url":"https://github.com/google/deck","last_synced_at":"2025-07-17T20:32:44.483Z","repository":{"id":63635203,"uuid":"545634980","full_name":"google/deck","owner":"google","description":"Deck provides a flexible logging framework for Go apps.","archived":false,"fork":false,"pushed_at":"2024-06-21T19:56:52.000Z","size":36,"stargazers_count":53,"open_issues_count":2,"forks_count":2,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-06-22T15:34:10.093Z","etag":null,"topics":["logging"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-04T18:08:06.000Z","updated_at":"2024-06-21T19:57:55.000Z","dependencies_parsed_at":"2024-06-18T21:28:58.783Z","dependency_job_id":"5fc4de5f-c17d-4bb2-9358-854fc6245d84","html_url":"https://github.com/google/deck","commit_stats":{"total_commits":23,"total_committers":3,"mean_commits":7.666666666666667,"dds":0.08695652173913049,"last_synced_commit":"3d02493294ab190ca5d099395e7c362b08034b98"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fdeck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fdeck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fdeck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fdeck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/deck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226304384,"owners_count":17603580,"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":["logging"],"created_at":"2024-11-25T09:28:43.314Z","updated_at":"2024-11-25T09:28:45.921Z","avatar_url":"https://github.com/google.png","language":"Go","readme":"# Deck - Flexible Logging Framework for Go\n\nThe Deck package provides a flexible logging framework for Go apps. Deck\nsupports Windows Event Log, syslog, Go's standard logging, logging to file, and\nlog replays for testing. Deck is extensible, so new log backends can integrate\nseamlessly into existing application code.\n\n## Standard Logging\n\nDeck can be a drop in replacement for some other logging packages, with support\nfor common functions like Info, Error, \u0026 Warning. The standard logging functions\nwrite their outputs immediately and don't support additional attributes.\n\n```\ndeck.Info(\"an info message\")\n```\n\n```\ndeck.Errorf(\"an %v message\", errors.New(\"error!\"))\n```\n\n## Extensible Logging with Attributes\n\nSometimes we want to be able to pass more complex inputs to our log messages.\nDeck facilitates this by allowing custom attributes to be attached to log\nmessages.\n\nWhen using the `A`ttribute-supporting log functions, the message isn't output\nimmediately. We use the `With()` function to attach additional metadata to the\nmessage first. The metadata can be anything supported by an attached\n[backend](#backends). Once fully marked up with attributes, the `Go()` function\nthen performs the final write of the message.\n\nIn this example, a log message is marked with *Verbosity* level 2.\n[Verbosity](#message-verbosity) can be used to dynamically show or hide log\nevents at runtime.\n\n```\ndeck.InfoA(\"a verbose message\").With(deck.V(2)).Go()\n```\n\nThe EventLog backend for Windows supports Event IDs:\n\n```\ndeck.InfoA(\"a windows event\").With(eventlog.EventID(123)).Go()\n```\n\nMultiple attributes can be attributed to the same message:\n\n```\ndeck.InfoA(\"a verbose windows event\").With(eventlog.EventID(123), deck.V(3)).Go()\n```\n\n## Backends\n\nDeck's logging functionality revolves around **backends**. A backend is any\nlogging destination that deck should write messages to. Backends are\nplug-and-play, so you can reconfigure your application's logging behavior simply\nby adding and removing different backends.\n\n```\nimport (\n  \"github.com/google/deck\"\n  \"github.com/google/deck/backends/logger\"\n)\n\ndeck.Add(logger.Init(os.Stdout, 0))\n```\n\nCross-platform builds can support platform-specific log outputs by calling `Add`\nfrom platform-specific source files.\n\n```\n// my_app_windows.go\n\nfunc init() {\n  evt, err := eventlog.Init(\"My App\")\n  if err != nil {\n    panic(err)\n  }\n  deck.Add(evt)\n}\n```\n\n```\n// my_app_linux.go\n\nfunc init() {\n  sl, err := syslog.Init(\"my-app\", syslog.LOG_USER)\n  if err != nil {\n    panic(err)\n  }\n  deck.Add(sl)\n}\n```\n\n### eventlog Backend\n\nThe eventlog backend is for Windows only. This backend supports logging to the\nWindows Event Log. It exports the `EventID` attribute that allows logging\nmessages with custom Event IDs.\n\n[eventlog Documentation](backends/eventlog/README.md).\n\n### logger Backend\n\nThe logger backend is based on Go's core `log` package. It can take any\nio.Writer, including os.Stdout, os.Stderr, io.Multiwriter, and any open file\nhandles.\n\n[logger Documentation](backends/logger/README.md).\n\n### syslog Backend\n\nThe syslog backend is based on Go's core `syslog` package for Linux/Unix.\n\n[syslog Documentation](backends/syslog/README.md).\n\n### discard Backend\n\nThe discard backend discards all log events. Deck requires at least one backend\nto be registered to handle logs. To suppress all output, add the discard\nbackend.\n\n[discard Documentation](backends/discard/README.md).\n\n### glog Backend\n\nThe glog backend provides support for logging to the glog package from\ngithub.com/golang/glog. This backend supports the Depth attribute as well as\nexporting a V() attribute for glog's V-style logging.\n\n[glog Documentation](backends/glog/README.md).\n\n### replay Backend\n\nThe replay backend provides the ability to record and replay log events for use\nin testing.\n\n[replay Documentation](backends/replay/README.md).\n\n## Message Verbosity\n\nVerbosity is a special attribute implemented by the deck core package. The `V()`\nfunction decorates logs with a custom verbosity, and the `SetVerbosity()`\nfunction determines which verbosity levels get output. This allows the verbosity\nlevel to be changed at runtime, such as via a flag or setting.\n\n```\ndeck.SetVerbosity(*verbosityFlag)\n...\nlog.InfoA(\"a level one message\").With(deck.V(1)).Go()\nlog.InfoA(\"a level three message\").With(deck.V(3)).Go()\n```\n\nIn this example, if verbosityFlag is 2 or lower, only *\"a level one message\"*\nwill print. If it's 3 or higher, both messages will print. Verbosity defaults to\n0, and all non-`A`ttribute functions will be at verbosity 0.\n\n## Custom Decks\n\nThe `deck` package builds a global deck whenever it's imported, and most\nimplementations can just use this deck directly via the package-level logging\nfunctions. For more advanced use cases, multiple decks can be constructed using\n`deck.New()`. Each deck can have its own set of attached backends, and supports\nthe same functionality as the global deck.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fdeck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Fdeck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fdeck/lists"}