{"id":22239539,"url":"https://github.com/illarion/filerotate","last_synced_at":"2025-03-25T10:15:33.731Z","repository":{"id":265526516,"uuid":"896192544","full_name":"illarion/filerotate","owner":"illarion","description":"Rotates [log] files generated by any kind of logger that is capable to use io.Writer or io.WriteCloser in Golang","archived":false,"fork":false,"pushed_at":"2024-12-01T14:04:43.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-19T17:07:10.452Z","etag":null,"topics":["go","golang","log","logging","logrotate","rotate","slog"],"latest_commit_sha":null,"homepage":"","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/illarion.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":"2024-11-29T18:36:02.000Z","updated_at":"2024-12-01T14:04:46.000Z","dependencies_parsed_at":"2024-11-29T19:38:40.085Z","dependency_job_id":"8717cf90-0e74-49d9-a06d-71d8f889dcfa","html_url":"https://github.com/illarion/filerotate","commit_stats":null,"previous_names":["illarion/filerotate"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illarion%2Ffilerotate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illarion%2Ffilerotate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illarion%2Ffilerotate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illarion%2Ffilerotate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/illarion","download_url":"https://codeload.github.com/illarion/filerotate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245440578,"owners_count":20615633,"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","log","logging","logrotate","rotate","slog"],"created_at":"2024-12-03T03:19:55.175Z","updated_at":"2025-03-25T10:15:33.682Z","avatar_url":"https://github.com/illarion.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# filerotate\n\nRotates [log] files generated by any kind of [logger] that is capable to use io.Writer in golang.\nImplements io.WriteCloser interface.\n\n```mermaid\ngraph \u003e\n    A[Logger] --\u003e B[FileRotate = io.WriteCloser] \n    subgraph rotate files\n        B --\u003e C[our.log]\n        C --\u003e D[our.log.1]\n        D --\u003e E[our.log.2]\n        E --\u003e F[our.log.3]\n    end\n    F --\u003e G(delete)\n```\n\n## Configuration\n```golang\n// Options\ntype Options struct {\n  // FilePath full path to the log file (i.e our.log)\n  FilePath string\n  // Rotate log file count times before removing. If Rotate count is 0, old versions are removed rather than rotated, so that only our.log is present\n  Rotate int\n  // Size of the file to grow. When exceeded, file is rotated.\n  Size uint64\n  // File mode, like 0600\n  Mode os.FileMode\n  // LineSeparator is the separator for the rotated files content\n  // If specified, rotated files will be split only when the separator is found in the\n  // content of the file.\n  LineSeparator []byte\n}\n\n// there are predefined line separators, but you can use your own\nvar (\n  LineSeparatorUnix    = []byte(\"\\n\")\n  LineSeparatorWindows = []byte(\"\\r\\n\")\n  LineSeparatorMac     = []byte(\"\\r\")\n  LineSeparatorNothing = []byte{}\n)\n\n```\n## Binary vs Text \n\nfilerotate is not limited to text files and can handle writing binary files, rotated by size or size + line separator, that can be any sequence of bytes specified, not limited to \"\\n\", \"\\r\\n\" or \"\\r\". \nSplitting the files does not happen at exaclty `Options.Size` byte and depends on the size of the buffer provided to `io.Writer.Write(buf)`, so that binary files may get corrupted.\n\n## Usage\n\n```golang\npackage main\n\nimport (\n\t\"log\"\n\t\"github.com/illarion/filerotate\"\n)\n\nfunc main() {\n    // Create a new file rotate\n    fr, err := filerotate.New(filerotate.Options{\n        FilePath: \"our.log\",\n        Rotate:   3,\n        Size:     1024,\n        Mode:     0600,\n        LineSeparator: filerotate.LineSeparatorUnix,\n    })\n    \n    if err != nil {\n        log.Fatal(err)\n    }\n   \n    // Connect log to the rotating writer\n    log.SetOutput(fr)\n\n    // Write to log number of times\n    for i := 0; i \u003c 10000; i++ {\n        log.Printf(\"Hello, world %d\\n\", i)\n    }\n}\n```\n\nafter runing the code, you will see the following files in the director\n\n```log\n~# go run main.go\n\n~# ls -1\nour.log\nour.log.1\nour.log.2\nour.log.3\n```\n\n## License\nMIT (see [LICENSE](LICENSE))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fillarion%2Ffilerotate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fillarion%2Ffilerotate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fillarion%2Ffilerotate/lists"}