{"id":36515523,"url":"https://github.com/myron-meng/sloginit","last_synced_at":"2026-01-14T19:27:12.599Z","repository":{"id":253502779,"uuid":"842985974","full_name":"myron-meng/sloginit","owner":"myron-meng","description":"sloginit is a Go log/slog wrapper that provides easy-to-use functions for initializing and configuring log/slog in your Go applications.","archived":false,"fork":false,"pushed_at":"2024-09-04T22:29:51.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-12T05:18:31.669Z","etag":null,"topics":["go","logging","structured-logging"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/myron-meng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-15T14:33:35.000Z","updated_at":"2024-09-04T22:29:06.000Z","dependencies_parsed_at":"2024-09-05T17:54:30.502Z","dependency_job_id":"e90902f1-a6d4-4699-b078-0711caf48123","html_url":"https://github.com/myron-meng/sloginit","commit_stats":null,"previous_names":["myron-meng/logr"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/myron-meng/sloginit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myron-meng%2Fsloginit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myron-meng%2Fsloginit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myron-meng%2Fsloginit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myron-meng%2Fsloginit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/myron-meng","download_url":"https://codeload.github.com/myron-meng/sloginit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myron-meng%2Fsloginit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28432604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["go","logging","structured-logging"],"created_at":"2026-01-12T02:40:54.801Z","updated_at":"2026-01-14T19:27:12.583Z","avatar_url":"https://github.com/myron-meng.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sloginit Package\n\nsloginit is a Go `log/slog` wrapper that provides easy-to-use functions for initializing and configuring `log/slog` in your Go applications.\n\n## Features\n\n- Easy initialization with sensible defaults\n- Support for logging to stdout and files\n- File rotation capabilities\n- Customizable log levels\n- Option to include source code location in logs\n- Customizable time format\n\n## Installation\n\nTo use this package, run:\n\n```\ngo get github.com/myron-meng/sloginit\n```\n\n## Quick Start\n\n### Basic Usage (Logging to stdout)\n\nIf you only need to print logs to stdout, you can initialize the logger with a single line in your `main()` function:\n\n```go\npackage main\n\nimport \"github.com/myron-meng/sloginit\"\n\nfunc main() {\n    sloginit.Init()\n\n    // or set log level\n    // sloginit.InitSlog(sloginit.WithLevel(slog.LevelInfo))\n\n    // or set log level by function\n    // sloginit.InitSlog(sloginit.WithLevelFunc(func() slog.Level {\n    //     l := slog.LevelDebug\n    //     if os.Getenv(\"ENV\") == \"prod\" {\n    //         l = slog.LevelInfo\n    //     }\n    //     return l\n    // }))\n\n    // Your application code here\n}\n```\n\n### Logging to a File\n\nTo log to a file, use the `WithFileOutput` option with `DefaultFileOutputConfig`:\n\n```go\npackage main\n\nimport (\n    \"github.com/myron-meng/sloginit\"\n    \n    \"log/slog\"\n)\n\nfunc main() {\n    // Log to a relative path\n    sloginit.InitSlog(\n        sloginit.WithFileOutput(sloginit.DefaultFileOutputConfig(\"logs/app.log\")),\n        sloginit.WithLevel(slog.LevelInfo),\n    )\n    defer sloginit.Close()\n\n    // Or log to an absolute path\n    // sloginit.InitSlog(\n    //     sloginit.WithFileOutput(sloginit.DefaultFileOutputConfig(\"/var/logs/myapp/app.log\")),\n    //     sloginit.WithLevel(slog.LevelInfo),\n    // )\n    \n    // Your application code here\n}\n```\n\n### Customizing File Output\n\nThe `FileOutputConfig` struct allows you to customize various aspects of file logging:\n\n```go\nsloginit.InitSlog(\n    sloginit.WithFileOutput(sloginit.FileOutputConfig{\n        Filename:   \"logs/app.log\",\n        MaxSize:    100,  // 100 MB\n        MaxBackups: 3,    // Keep 3 old files\n        MaxAge:     28,   // 28 days\n        Compress:   true, // Compress old files\n    }),\n    sloginit.WithLevel(slog.LevelDebug),\n    sloginit.WithSource(true),\n)\ndefer sloginit.Close()\n```\n\n## Additional Options\n\n- `WithLevel(level slog.Level)`: Set a fixed log level\n- `WithLevelFunc(func() slog.Level)`: Set level based on a function\n- `WithSource(bool)`: Include source code location in logs\n- `WithTimeFormat(string)`: Customize the time format in logs\n\n## Using the Logger\n\nAfter initialization, you can use the standard `slog` functions to log messages:\n\n```go\nslog.Info(\"Application started\")\nslog.Debug(\"This is a debug message\")\nslog.Error(\"An error occurred\", \"error\", err)\n\n// For fatal errors\nsloginit.Fatal(\"A fatal error occurred\", \"error\", err)\n// or\nslog.Log(context.TODO(),  slog.Level(12), msg, args...)\n```\n\nFor more detailed information on `slog` usage, refer to the official Go documentation.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyron-meng%2Fsloginit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmyron-meng%2Fsloginit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyron-meng%2Fsloginit/lists"}