{"id":13413292,"url":"https://github.com/apsdehal/go-logger","last_synced_at":"2025-04-05T13:09:36.497Z","repository":{"id":57482077,"uuid":"24486800","full_name":"apsdehal/go-logger","owner":"apsdehal","description":"Simple logger for Go programs. Allows custom formats for messages.","archived":false,"fork":false,"pushed_at":"2019-05-15T21:27:11.000Z","size":90,"stargazers_count":289,"open_issues_count":3,"forks_count":52,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-29T12:11:14.260Z","etag":null,"topics":["golang","logger","logging-library"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apsdehal.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":"2014-09-26T04:57:06.000Z","updated_at":"2024-12-18T01:53:55.000Z","dependencies_parsed_at":"2022-09-02T06:11:11.455Z","dependency_job_id":null,"html_url":"https://github.com/apsdehal/go-logger","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apsdehal%2Fgo-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apsdehal%2Fgo-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apsdehal%2Fgo-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apsdehal%2Fgo-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apsdehal","download_url":"https://codeload.github.com/apsdehal/go-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339158,"owners_count":20923014,"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":["golang","logger","logging-library"],"created_at":"2024-07-30T20:01:36.987Z","updated_at":"2025-04-05T13:09:36.472Z","avatar_url":"https://github.com/apsdehal.png","language":"Go","readme":"\n# go-logger\n\n[![Build Status](https://travis-ci.org/apsdehal/go-logger.svg?branch=master)](https://travis-ci.org/apsdehal/go-logger)\n[![GoDoc](https://godoc.org/github.com/apsdehal/go-logger?status.svg)](http://godoc.org/github.com/apsdehal/go-logger)\n\nA simple go logger for easy logging in your programs. Allows setting custom format for messages.\n\n# Preview\n\n[![Example Output](examples/example.png)](examples/example.go)\n\n\n# Install\n\n`go get github.com/apsdehal/go-logger`\n\nUse `go get -u` to update the package.\n\n# Example\n\nExample [program](examples/example.go) demonstrates how to use the logger. See below for __formatting__ instructions.\n\n\n```go\npackage main\n\nimport (\n\t\"github.com/apsdehal/go-logger\"\n\t\"os\"\n)\n\nfunc main () {\n\t// Get the instance for logger class, \"test\" is the module name, 1 is used to\n\t// state if we want coloring\n\t// Third option is optional and is instance of type io.Writer, defaults to os.Stderr\n\tlog, err := logger.New(\"test\", 1, os.Stdout)\n\tif err != nil {\n\t\tpanic(err) // Check for error\n\t}\n\n\t// Critically log critical\n\tlog.Critical(\"This is Critical!\")\n\tlog.CriticalF(\"%+v\", err)\n\t// You can also use fmt compliant naming scheme such as log.Criticalf, log.Panicf etc\n\t// with small 'f'\n\t\n\t// Debug\n\t// Since default logging level is Info this won't print anything\n\tlog.Debug(\"This is Debug!\")\n\tlog.DebugF(\"Here are some numbers: %d %d %f\", 10, -3, 3.14)\n\t// Give the Warning\n\tlog.Warning(\"This is Warning!\")\n\tlog.WarningF(\"This is Warning!\")\n\t// Show the error\n\tlog.Error(\"This is Error!\")\n\tlog.ErrorF(\"This is Error!\")\n\t// Notice\n\tlog.Notice(\"This is Notice!\")\n\tlog.NoticeF(\"%s %s\", \"This\", \"is Notice!\")\n\t// Show the info\n\tlog.Info(\"This is Info!\")\n\tlog.InfoF(\"This is %s!\", \"Info\")\n\n\tlog.StackAsError(\"Message before printing stack\");\n\n\t// Show warning with format\n\tlog.SetFormat(\"[%{module}] [%{level}] %{message}\")\n\tlog.Warning(\"This is Warning!\") // output: \"[test] [WARNING] This is Warning!\"\n\t// Also you can set your format as default format for all new loggers\n\tlogger.SetDefaultFormat(\"%{message}\")\n\tlog2, _ := logger.New(\"pkg\", 1, os.Stdout)\n\tlog2.Error(\"This is Error!\") // output: \"This is Error!\"\n\n\t// Use log levels to set your log priority\n\tlog2.SetLogLevel(DebugLevel)\n\t// This will be printed\n\tlog2.Debug(\"This is debug!\")\n\tlog2.SetLogLevel(WarningLevel)\n\t// This won't be printed\n\tlog2.Info(\"This is an error!\")\n}\n```\n\n\n# Formatting\n\nBy default all log messages have format that you can see above (on pic).\nBut you can override the default format and set format that you want.\n\nYou can do it for Logger instance (after creating logger) ...\n```go\nlog, _ := logger.New(\"pkgname\", 1)\nlog.SetFormat(format)\n```\n... or for package\n```go\nlogger.SetDefaultFormat(format)\n```\nIf you do it for package, all existing loggers will print log messages with format that these used already.\nBut all newest loggers (which will be created after changing format for package) will use your specified format.\n\nBut anyway after this, you can still set format of message for specific Logger instance.\n\nFormat of log message must contains verbs that represent some info about current log entry.\nOfc, format can contain not only verbs but also something else (for example text, digits, symbols, etc)\n\n### Format verbs:\nYou can use the following verbs:\n```\n%{id}           - means number of current log message\n%{module}       - means module name (that you passed to func New())\n%{time}\t\t\t- means current time in format \"2006-01-02 15:04:05\"\n%{time:format}\t- means current time in format that you want\n\t\t\t\t\t(supports all formats supported by go package \"time\")\n%{level}\t\t- means level name (upper case) of log message (\"ERROR\", \"DEBUG\", etc)\n%{lvl}\t\t\t- means first 3 letters of level name (upper case) of log message (\"ERR\", \"DEB\", etc)\n%{file} \t\t- means name of file in what you wanna write log\n%{filename}\t\t- means the same as %{file}\n%{line}\t\t\t- means line number of file in what you wanna write log\n%{message}\t\t- means your log message\n```\nNon-existent verbs (like ```%{nonex-verb}``` or ```%{}```) will be replaced by an empty string.\nInvalid verbs (like ```%{inv-verb```) will be treated as plain text.\n\n# Tests\n\nRun:\n- `go test logger` to run test on logger.\n- `go test -bench=.` for benchmarks.\n\n## Thanks\n\nThanks goes to all go-loggers out there which I used as reference.\n\n## Contributors\n\nFollowing contributors have made major contributions to go-logger:\n\n- [@qioalice](https://github.com/qioalice)\n- [@gjvnq](https://github.com/gjvnq)\n- [@maezen](https://github.com/maezen)\n\n## License\n\nThe [BSD 3-Clause license](http://opensource.org/licenses/BSD-3-Clause), the same as the [Go language](http://golang.org/LICENSE).\n","funding_links":[],"categories":["Logging","日志记录","Logging 日志库","Relational Databases","\u003cspan id=\"日志-logging\"\u003e日志 Logging\u003c/span\u003e","日志"],"sub_categories":["Search and Analytic Databases","Advanced Console UIs","检索及分析资料库","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapsdehal%2Fgo-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapsdehal%2Fgo-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapsdehal%2Fgo-logger/lists"}