{"id":20271926,"url":"https://github.com/point-c/wgevents","last_synced_at":"2026-05-14T05:38:21.262Z","repository":{"id":214015198,"uuid":"735500562","full_name":"point-c/wgevents","owner":"point-c","description":"wgevents is a package for getting detailed logging from wireguard-go","archived":false,"fork":false,"pushed_at":"2024-01-20T00:58:26.000Z","size":499,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T05:50:45.742Z","etag":null,"topics":["generated-code","golang","golang-library","templates","wireguard","wireguard-go"],"latest_commit_sha":null,"homepage":"https://point-c.github.io/wgevents/","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/point-c.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-25T06:41:51.000Z","updated_at":"2024-01-27T07:30:54.000Z","dependencies_parsed_at":"2023-12-25T07:21:10.113Z","dependency_job_id":"4733c377-2abc-4ef1-91f0-820db0787c74","html_url":"https://github.com/point-c/wgevents","commit_stats":null,"previous_names":["point-c/wgevents"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgevents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgevents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgevents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgevents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/point-c","download_url":"https://codeload.github.com/point-c/wgevents/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241758962,"owners_count":20015251,"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":["generated-code","golang","golang-library","templates","wireguard","wireguard-go"],"created_at":"2024-11-14T12:40:02.707Z","updated_at":"2026-05-14T05:38:21.219Z","avatar_url":"https://github.com/point-c.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wgevents\n\n[![Go Reference](https://img.shields.io/badge/godoc-reference-%23007d9c.svg)](https://point-c.github.io/wgevents)\n\n## Overview\n\n`wgevents` is a logging package for [`wireguard-go`](https://github.com/WireGuard/wireguard-go). It transforms format strings and args passed to logger methods into concrete events.\n\n## Key Features\n\n- **Event-based Logging:** Converts format strings and arguments into concrete logging events.\n- **Structured Logging Support:** logs format arguments separate slog records. Integrates with `slog.Logger`.\n- **Wireguard-go Version Pinning:** The package is designed as a separate module to pin to a specific version of `wireguard-go`. This ensures compatibility and stability even when `wireguard-go` messages change.\n\n## Installation\n\nTo use wgevents in your Go project, install it using `go get`:\n\n```bash\ngo get github.com/point-c/wgevents\n```\n\n## Usage\n\n### Events Function\n\nThe `Events` function creates a new `device.Logger` capable of recognizing names and types of arguments passed to logging methods.\n\n```go\nfunc Events(fn func(Event)) *device.Logger\n```\n\n#### Parameters:\n- `fn func(Event)`: A callback function that is called for each event logged.\n\n#### Returns:\n- `*device.Logger`: A logger compatible with `wireguard-go`.\n\n### Event Handling\n\nEach logged event is handled through the provided callback function. \nThe package handles known events with specific types, and unknown events are categorized as `EventAny`.\n\n## Example\n\n### Basic Usage\n\n```go\nlogger := wgevents.Events(func(e wgevents.Event) {\n    // Handle logging event\n})\n// Use logger in your application\n```\n\n### Recognizing Events\n\nA type switch can be used to recognize specific events:\n\n```go\nswitch ev := ev.(type) {\ncase *wgevents.EventAssumingDefaultMTU:\ncase *wgevents.EventBindCloseFailed:\ncase *wgevents.EventBindUpdated:\n// And so on...\n}\n```\n\n### Logging\n\n```go\nlogger := wgevents.Events(func(e wgevents.Event) {\n    e.Slog(slog.Default())\n})\n```\n\n## Contributing\n\nThis package allows for updates and additions of events. Modify `internal/events-generate/events.yml` and regenerate `events_generated.go` to update event handling.\n\n### File Layout\n\nEach section under the `events` key corresponds to a specific event that can be logged:\n\n```yaml\n\u003cevent name\u003e:\n    type: string\n    level: string\n    nice: string (optional)\n    format: string\n    args: list (optional)\n    custom: bool (optional)\n```\n\n### Key Definitions\n\n- `type`: The type of logging or messaging method to be used. Only `errorf` for error logging, and `verbosef` for verbose logging are valid.\n- `level`: The level at which the logging should occur. Valid values are `debug`, `info`, `warn`, and `error`.\n- `nice`: An optional human-readable message for the event. If not specified `format` will be used.\n- `format`: The format string used by the `wireguard-go` library.\n- `args`: The arguments used in the format string in the following format:\n  \n    ```yaml\n    - \u003cname\u003e: \u003ctype\u003e\n    - \u003cname\u003e: \u003ctype\u003e\n    ```\n\n- `custom`: An optional flag indicating that parsing this event requires custom logic to be implemented.\n\n### Imports\n\nThe final section of the configuration file lists the external packages used as part of the event processing mechanism. These are mentioned under the `imports` key.\n\n## Testing\n\nThe package includes tests that demonstrate its functionality. Use Go's testing tools to run the tests:\n\n```bash\ngo test ./...\n```\n\n## Godocs\n\nTo regenerate godocs:\n\n```bash\ngo generate -tags docs ./...\n```\n\n## Code Generation\n\nTo regenerate generated packages:\n\n```bash\ngo generate ./...\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoint-c%2Fwgevents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoint-c%2Fwgevents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoint-c%2Fwgevents/lists"}