{"id":28411173,"url":"https://github.com/wnderbin/chronolog","last_synced_at":"2025-09-03T04:38:16.821Z","repository":{"id":295944550,"uuid":"991332020","full_name":"wnderbin/ChronoLog","owner":"wnderbin","description":"ChronoLog is a convenient, lightweight and understandable logger for Golang.","archived":false,"fork":false,"pushed_at":"2025-06-06T14:11:17.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-25T08:41:53.386Z","etag":null,"topics":["go","go-package","golang","logger","logging","logging-tool","package","tool"],"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/wnderbin.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":"2025-05-27T13:17:50.000Z","updated_at":"2025-06-06T14:11:19.000Z","dependencies_parsed_at":"2025-06-06T15:21:01.274Z","dependency_job_id":null,"html_url":"https://github.com/wnderbin/ChronoLog","commit_stats":null,"previous_names":["wnderbin/chronolog"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/wnderbin/ChronoLog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnderbin%2FChronoLog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnderbin%2FChronoLog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnderbin%2FChronoLog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnderbin%2FChronoLog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wnderbin","download_url":"https://codeload.github.com/wnderbin/ChronoLog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnderbin%2FChronoLog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273392280,"owners_count":25097256,"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","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","go-package","golang","logger","logging","logging-tool","package","tool"],"created_at":"2025-06-02T14:15:12.977Z","updated_at":"2025-09-03T04:38:16.804Z","avatar_url":"https://github.com/wnderbin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ChronoLog\n**Convenient, lightweight and understandable logging-tool for Golang.**\n\n[![ChronoLog-Tests](https://github.com/wnderbin/ChronoLog/actions/workflows/chronolog_tests.yml/badge.svg)](https://github.com/wnderbin/ChronoLog/actions/workflows/chronolog_tests.yml)\n\nChronoLog is designed as part of a logging system, as it works well with files. It is not a complete solution, but only a component for working with logging and its management.\n\nChronoLog is a package for writing logs to files. The package is a lightweight and easy-to-use tool that writes data in json format and in plain text.\n\nThe package was created with an emphasis on the extensibility of its components, scalability and flexibility. You can change its functionality at your discretion, as well as extend it. It has a simple source code, which will allow anyone to easily change the functionality of this tool.\n\nChronoLog assumes that only one process will write. If logs are written by several processes with the same configuration, this may lead to incorrect behavior.\n\n## ChronoLog Features\n- [ ] `Writing logs to console`\n- [X] `Writing logs in JSON format`\n- [X] `Writing logs in plain text format`\n- [X] `Compress large logs into .gz extension`\n- [X] `Self-cleaning of old logs`\n- [X] `Works well with multithreading`\n\n\n### Installing a package into your project\nYou can install the package into your project using the command below.\n```\ngo get github.com/wnderbin/ChronoLog\n```\n### Quick start\nOnce you install this package, you can use it immediately.\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\tchronolog \"github.com/wnderbin/ChronoLog\"\n)\n\nfunc main() {\n\tconf := chronolog.Config{\n\t\tFilePath:              \"logs.json\",\n\t\tMaxSize:               432,\n\t\tMaxAge:                time.Second * 5,\n\t\tCompressOldLogs:       true,\n\t\tJSONFormat:            true,\n\t\tTimestampFormat:       time.RFC3339,\n\t\tRotationCheckInterval: time.Second * 5,\n\t}\n\tchronologger, err := chronolog.New(conf)\n\tif err != nil {\n\t\tfmt.Println(\"Error from chronolog/New(): %w\", err)\n\t}\n\n\tfor {\n\t\tchronologger.Debug(\"debug message\")\n\t\tchronologger.Error(\"error message\")\n\t\tchronologger.Fatal(\"fatal message\")\n\t\tchronologger.Info(\"info message\")\n\t\tchronologger.Warning(\"warning message\")\n\t\ttime.Sleep(5 * time.Second)\n\t}\n}\n```\n\n#### Let's take a closer look at the code\n1. **Setting up the logger configuration.\nThe configuration has the following fields:**\n```\ntype Config struct {\n\tFilePath              string\n\tMaxSize               int64         \n\tMaxAge                time.Duration\n\tCompressOldLogs       bool          \n\tJSONFormat            bool          \n\tTimestampFormat       string        \n\tRotationCheckInterval time.Duration \n}\n```\n* **FilePath** - Path to the file where logs should be written. If the file is missing, ChronoLog will initialize it automatically.\n* **MaxSize** - Maximum log size, specified in bytes. The default log size is 50 megabytes. If the logs exceed this size, the file will be compressed depending on the settings you specify below. If you do not need to compress the log file, ChronoLog will simply save the file with the date at the time the file overflowed.\n* **MaxAge** - Maximum storage time for overflow/compressed files.\n* **CompressOldLogs** - Parameter, if true is specified - when the file is resized, it will start compressing it with the extension .gz. Otherwise, compression will not occur.\n* **JSONFormat** - The parameter that is responsible for writing the file in JSON format. If true is specified, the file will be written in JSON format. Otherwise, it will be written in plain text format.\n* **TimestampFormat** - Parameter that specifies the time format in which logs should be written.\n* **RotationCheckInterval** - The period of checking the file overflow and performing its rotation.\n\n2. **Creating a logger**\nThe logger is created using the New() function, which returns the logger object and the error, if any. Using the received object, you can write logs to the file specified in the configuration. The New() function also sets default settings if none have been specified.\n```\nchronologger, err := chronolog.New(conf)\n```\n```\nfunc New(config Config) (*Logger, error) {\n\tif config.MaxSize == 0 {\n\t\tconfig.MaxSize = 50 * 1024 * 1024 // default size = 50MB\n\t}\n\tif config.MaxAge == 0 {\n\t\tconfig.MaxAge = 7 * 24 * time.Hour // default max age = 1 week\n\t}\n\tif config.TimestampFormat == \"\" {\n\t\tconfig.TimestampFormat = time.RFC3339 // default timestamp format = \"2006-01-02T15:04:05Z07:00\"\n\t}\n\tif config.RotationCheckInterval == 0 {\n\t\tconfig.RotationCheckInterval = time.Minute // check rotation every minute\n\t}\n\n\tl := \u0026Logger{\n\t\tconfig:   config,\n\t\tquitChan: make(chan struct{}),\n\t}\n\n\tif err := l.openFile(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tgo l.rotationChecker()\n\n\treturn l, nil\n}\n```\n\n3. **Writing logs. As mentioned above, writing logs will be done via the object reference you got earlier from the New() function.**\n```\nchronologger, err := chronolog.New(conf)\nif err != nil {\n\tfmt.Println(\"Error from chronolog/New(): %w\", err)\n}\nchronologger.Debug(\"debug message\")\nchronologger.Error(\"error message\")\nchronologger.Fatal(\"fatal message\")\nchronologger.Info(\"info message\")\nchronologger.Warning(\"warning message\")\n```\n\n4. After using the logger, you can close it using the Close() function. This will stop it from consuming resources and close the file.\n```\nchronologger.Close()\n```\n```\nfunc (l *Logger) Close() error {\n\tclose(l.quitChan)\n\tl.mu.Lock()\n\tdefer l.mu.Unlock()\n\n\tif l.file != nil {\n\t\treturn l.file.Close()\n\t}\n\treturn nil\n}\n```\n\n### Author\n* wnderbin\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwnderbin%2Fchronolog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwnderbin%2Fchronolog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwnderbin%2Fchronolog/lists"}