{"id":20968821,"url":"https://github.com/phachon/go-logger","last_synced_at":"2025-04-07T05:10:38.926Z","repository":{"id":47702277,"uuid":"105351818","full_name":"phachon/go-logger","owner":"phachon","description":" 一个简单而强大的 golang 日志工具包，支持同步和异步输出到 命令行，文件, api 接口，文件支持按文件大小，文件行数，日期切分;A simple and powerful golang logging toolkit that supports synchronous and asynchronous output to the console, file, API interfaces, file support by file size, file line number, date sharding.","archived":false,"fork":false,"pushed_at":"2020-11-28T04:18:06.000Z","size":97,"stargazers_count":182,"open_issues_count":11,"forks_count":59,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-30T21:14:01.132Z","etag":null,"topics":["console","console-color","console-log","file","filelogger","go","go-study","golang","golang-learning","golang-study","javascript","log","logger","php","php-log","php-logger","syslog"],"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/phachon.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}},"created_at":"2017-09-30T07:38:23.000Z","updated_at":"2024-08-13T09:26:14.000Z","dependencies_parsed_at":"2022-08-28T17:40:51.022Z","dependency_job_id":null,"html_url":"https://github.com/phachon/go-logger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phachon%2Fgo-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phachon%2Fgo-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phachon%2Fgo-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phachon%2Fgo-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phachon","download_url":"https://codeload.github.com/phachon/go-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595335,"owners_count":20963943,"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":["console","console-color","console-log","file","filelogger","go","go-study","golang","golang-learning","golang-study","javascript","log","logger","php","php-log","php-logger","syslog"],"created_at":"2024-11-19T03:16:54.084Z","updated_at":"2025-04-07T05:10:38.901Z","avatar_url":"https://github.com/phachon.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-logger\nA simple but powerful golang log Toolkit  \n\n[![Sourcegraph](https://sourcegraph.com/github.com/phachon/go-logger/-/badge.svg)](https://sourcegraph.com/github.com/phachon/go-logger?badge)\n[![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/phachon/go-logger) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/phachon/go-logger/master/LICENSE)\n\n[中文文档](/README_CN.md)\n\n# Feature\n- Support at the same time to console, file, URL\n- console output fonts can be colored with\n- File output supports three types of segmentation based on the size of the file, the number of file lines, and the date.\n- file output support is saved to different files at the log level.\n- Two ways of writing to support asynchronous and synchronous\n- Support json format output\n- The code is designed to be extensible, and you can design your own adapter as needed\n\n# Install\n\n```\ngo get github.com/phachon/go-logger\ngo get ./...\n```\n\n# Requirement\ngo 1.8\n\n# Support outputs\n- console  // write console\n- file     // write file\n- api      // http request url\n- ...\n\n\n# Quick Used\n\n- sync\n\n```\nimport (\n    \"github.com/phachon/go-logger\"\n)\nfunc main()  {\n    logger := go_logger.NewLogger()\n\n    logger.Info(\"this is a info log!\")\n    logger.Errorf(\"this is a error %s log!\", \"format\")\n}\n```\n\n- async\n\n```\nimport (\n    \"github.com/phachon/go-logger\"\n)\nfunc main()  {\n    logger := go_logger.NewLogger()\n    logger.SetAsync()\n\n    logger.Info(\"this is a info log!\")\n    logger.Errorf(\"this is a error %s log!\", \"format\")\n\n    // Flush must be called before the end of the process\n    logger.Flush()\n}\n```\n\n- Multiple output\n\n```\nimport (\n    \"github.com/phachon/go-logger\"\n)\nfunc main()  {\n    logger := go_logger.NewLogger()\n\n    logger.Detach(\"console\")\n\n    // console adapter config\n    consoleConfig := \u0026go_logger.ConsoleConfig{\n        Color: true, // Does the text display the color\n        JsonFormat: true, // Whether or not formatted into a JSON string\n        Format: \"\", // JsonFormat is false, logger message output to console format string\n    }\n    // add output to the console\n    logger.Attach(\"console\", go_logger.LOGGER_LEVEL_DEBUG, consoleConfig)\n\n    // file adapter config\n    fileConfig := \u0026go_logger.FileConfig {\n        Filename : \"./test.log\", // The file name of the logger output, does not exist automatically\n        // If you want to separate separate logs into files, configure LevelFileName parameters.\n        LevelFileName : map[int]string {\n            logger.LoggerLevel(\"error\"): \"./error.log\",    // The error level log is written to the error.log file.\n            logger.LoggerLevel(\"info\"): \"./info.log\",      // The info level log is written to the info.log file.\n            logger.LoggerLevel(\"debug\"): \"./debug.log\",    // The debug level log is written to the debug.log file.\n        },\n        MaxSize : 1024 * 1024,  // File maximum (KB), default 0 is not limited\n        MaxLine : 100000, // The maximum number of lines in the file, the default 0 is not limited\n        DateSlice : \"d\",  // Cut the document by date, support \"Y\" (year), \"m\" (month), \"d\" (day), \"H\" (hour), default \"no\".\n        JsonFormat: true, // Whether the file data is written to JSON formatting\n        Format: \"\", // JsonFormat is false, logger message written to file format string\n    }\n    // add output to the file\n    logger.Attach(\"file\", go_logger.LOGGER_LEVEL_DEBUG, fileConfig)\n\n\n    logger.Info(\"this is a info log!\")\n    logger.Errorf(\"this is a error %s log!\", \"format\")\n}\n```\n\n## Console text with color effect\n![image](https://github.com/phachon/go-logger/blob/master/_example/images/console.png)\n\n## Customize Format output\n\n### Logger Message\n\n| Field | Alias |Type  | Comment | Example |\n|-------|-------|------|---------|----------|\n| Timestamp | timestamp | int64 | unix timestamp| 1521791201 |\n| TimestampFormat | timestamp_format| string | timestamp format | 2018-3-23 15:46:41|\n| Millisecond | millisecond | int64 | millisecond | 1524472688352 |\n| MillisecondFormat | millisecond_format| string | millisecond_format | 2018-3-23 15:46:41.970 |\n| Level | level| int | logger level |  1  |\n| LevelString | level_string | string | logger level string | Error |\n| Body | body | string | logger message body | this is a info log |\n| File | file | string | Call the file of the logger | main.go |\n| Line | line | int | The number of specific lines to call logger |64|\n| Function | function| string | The function name to call logger  | main.main |\n\n\u003e\u003e If you want to customize the format of the log output ?\n\n**config format**:\n```\nconsoleConfig := \u0026go_logger.ConsoleConfig{\n    Format: \"%millisecond_format% [%level_string%] %body%\",\n}\nfileConfig := \u0026go_logger.FileConfig{\n    Format: \"%millisecond_format% [%level_string%] %body%\",\n}\n```\n**output**:\n```\n2018-03-23 14:55:07.003 [Critical] this is a critical log!\n```\n\n\u003e\u003e You can customize the format, Only needs to be satisfied Format: \"%Logger Message Alias%\"\n\n## More adapter examples\n- [console](./_example/console.go)\n- [file](./_example/file.go)\n- [api](./_example/api.go)\n\n\n## Benchmark\n\nsystem: Linux Mint 18.2 Sonya  \ncpu(s): 4  \nmodel name: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz  \nmemery: 4G  \n\n```\nBenchmarkLoggerConsoleText          500000             11375 ns/op             672 B/op         15 allocs/op\nBenchmarkLoggerConsoleText-2        500000             11345 ns/op             672 B/op         15 allocs/op\nBenchmarkLoggerConsoleText-4        500000              9897 ns/op             672 B/op         15 allocs/op\n```\n\n```\nBenchmarkLoggerConsoleAsyncText     500000              9323 ns/op             672 B/op         15 allocs/op\nBenchmarkLoggerConsoleAsyncText-2   500000              9087 ns/op             672 B/op         15 allocs/op\nBenchmarkLoggerConsoleAsyncText-4   500000             10685 ns/op             672 B/op         15 allocs/op\n```\n\n```\nBenchmarkLoggerConsoleJson          200000             30918 ns/op            2048 B/op         10 allocs/op\nBenchmarkLoggerConsoleJson-2        200000             33153 ns/op            2048 B/op         10 allocs/op\nBenchmarkLoggerConsoleJson-4        200000             30918 ns/op            2048 B/op         10 allocs/op\n```\n\n```\nBenchmarkLoggerFileText             300000             14083 ns/op             912 B/op         21 allocs/op\nBenchmarkLoggerFileText-2           200000             21159 ns/op             912 B/op         21 allocs/op\nBenchmarkLoggerFileText-4           200000             23776 ns/op             912 B/op         21 allocs/op\n```\n\n```\nBenchmarkLoggerFileAsyncText        300000             13956 ns/op             912 B/op         21 allocs/op\nBenchmarkLoggerFileAsyncText-2      300000             16124 ns/op             912 B/op         21 allocs/op\nBenchmarkLoggerFileAsyncText-4      300000             18641 ns/op             912 B/op         21 allocs/op\n```\n\n```\nBenchmarkLoggerFileJson             200000             15472 ns/op            1968 B/op         15 allocs/op\nBenchmarkLoggerFileJson-2           200000             22523 ns/op            1968 B/op         15 allocs/op\nBenchmarkLoggerFileJson-4           200000             25596 ns/op            1968 B/op         15 allocs/op\n```\n\n## Reference\nbeego/logs : github.com/astaxie/beego/logs\n\n## Feedback\n\nWelcome to submit comments and code, contact information phachon@163.com\n\n## License\n\nMIT\n\nThanks\n---------\nCreate By phachon@163.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphachon%2Fgo-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphachon%2Fgo-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphachon%2Fgo-logger/lists"}