{"id":16879664,"url":"https://github.com/easycz/logrotate","last_synced_at":"2025-06-21T21:07:15.458Z","repository":{"id":57510929,"uuid":"237676949","full_name":"easyCZ/logrotate","owner":"easyCZ","description":"Concurrency safe log rotating writer for Golang","archived":false,"fork":false,"pushed_at":"2024-05-02T13:24:23.000Z","size":31,"stargazers_count":28,"open_issues_count":5,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T12:13:07.851Z","etag":null,"topics":["go","golang","logging","writer"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/easyCZ/logrotate","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/easyCZ.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,"zenodo":null}},"created_at":"2020-02-01T20:58:25.000Z","updated_at":"2025-04-07T03:29:45.000Z","dependencies_parsed_at":"2025-04-11T11:43:51.549Z","dependency_job_id":"25a6808b-449e-401f-9a6d-8e2dde5912fc","html_url":"https://github.com/easyCZ/logrotate","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/easyCZ/logrotate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Flogrotate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Flogrotate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Flogrotate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Flogrotate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/easyCZ","download_url":"https://codeload.github.com/easyCZ/logrotate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Flogrotate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261193127,"owners_count":23122909,"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":["go","golang","logging","writer"],"created_at":"2024-10-13T15:55:14.621Z","updated_at":"2025-06-21T21:07:10.407Z","avatar_url":"https://github.com/easyCZ.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# logrotate\nConcurrency safe logging writer for Golang for application-side log rotation.\n\n## Motivation\nIn general, application-side log rotation should be avoided. Log rotation is best done through [logrotate](https://linux.die.net/man/8/logrotate) and other tools. \nHowever, some applications are constrained to only application-side log rotation and benefit from this package.\n\n## Usage\n```\ngo get github.com/easyCZ/logrotate\n```\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"time\"\n    \n    \"github.com/easyCZ/logrotate\"\n)\n\nfunc main() {\n\tlogger := log.New(os.Stderr, \"logrotate\", log.LstdFlags) // Or any other logger conforming to golang's log.Logger\n\twriter, err := logrotate.New(logger, logrotate.Options{\n        // Where should the writer be outputting files?\n        // If the directory does not exist, it will be created.\n        // Required.\n\t\tDirectory:       \"path/to/my/logs/directory\",\n        // What is the maximum size of each file?\n        // Optional. Use 0 for unlimited.\n\t\tMaximumFileSize: 1024 * 1024 * 1024,\n        // How often should a new file be created, based on time?\n        // Optional. Use 0 to disable time based log rotation.\n\t\tMaximumLifetime: time.Hour,\n        // How would you like to name your files?\n        // Invoked each time a new file is being created.\n        FileNameFunc:    logrotate.DefaultFilenameFunc,\n\t})\n\tif err != nil {\n\t\t// handle err\n\t}\n    \n    // ...\n    \n    // Ensure all messages are flushed to files before exiting \n    if err := writer.Close(); err != nil {\n        // handle err\n    }   \n}\n```\n\n### Usage with Golang's log.Logger\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/easyCZ/logrotate\"\n)\n\nfunc main() {\n\t// Write logrotate's own log lines to stderr\n\tstderrLogger := log.New(os.Stderr, \"logrotate\", log.LstdFlags)\n\n\twriter, err := logrotate.New(stderrLogger, logrotate.Options{\n\t\tDirectory: \"/path/to/my/logs\",\n\t\t// see other options above\n\t})\n\n\t// Your application logger, using logrotate as the backing Writer implementation.\n\tlogger := log.New(writer, \"application\", log.LstdFlags)\n\n    // Ensure all messages are flushed to files before exiting \n    if err := writer.Close(); err != nil {\n        // handle err\n    }  \n}\n```\n\n### Usage with logrus\n```go\npackage main\n\nimport (\n\t\"os\"\n\tlog \"github.com/sirupsen/logrus\"\n\tlogrotate \"github.com/easyCZ/logrotate\"\n)\n\nfunc init() {\n\twriter, err := logrotate.New(logger, logrotate.Options{\n\t\tDirectory: \"path/to/my/logs/directory\",\n\t})\n\tif err != nil {\n\t\t// handle err\n\t}\n\t// Output to stdout instead of the default stderr\n\t// Can be any io.Writer, see below for File example\n\tlog.SetOutput(writer)\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasycz%2Flogrotate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasycz%2Flogrotate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasycz%2Flogrotate/lists"}