{"id":13413291,"url":"https://github.com/ian-kent/go-log","last_synced_at":"2025-08-23T02:06:32.999Z","repository":{"id":16607280,"uuid":"19361990","full_name":"ian-kent/go-log","owner":"ian-kent","description":"A logger, for Go","archived":false,"fork":false,"pushed_at":"2018-03-31T02:06:55.000Z","size":38,"stargazers_count":43,"open_issues_count":3,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-25T05:23:00.971Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ian-kent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-02T00:34:09.000Z","updated_at":"2024-06-13T21:18:10.000Z","dependencies_parsed_at":"2022-09-26T20:52:51.357Z","dependency_job_id":null,"html_url":"https://github.com/ian-kent/go-log","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ian-kent%2Fgo-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ian-kent%2Fgo-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ian-kent%2Fgo-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ian-kent%2Fgo-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ian-kent","download_url":"https://codeload.github.com/ian-kent/go-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230542288,"owners_count":18242332,"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":[],"created_at":"2024-07-30T20:01:36.965Z","updated_at":"2024-12-20T06:06:37.520Z","avatar_url":"https://github.com/ian-kent.png","language":"Go","funding_links":[],"categories":["Logging","Logging 日志库","Relational Databases","日志","日志记录","\u003cspan id=\"日志-logging\"\u003e日志 Logging\u003c/span\u003e"],"sub_categories":["Advanced Console UIs","SQL 查询语句构建库","Search and Analytic Databases","交流","检索及分析资料库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"Go-Log\n======\n\n[![Build Status](https://travis-ci.org/ian-kent/go-log.svg?branch=master)](https://travis-ci.org/ian-kent/go-log)\n\nA logger, for Go!\n\nIt's sort of ```log``` and ```code.google.com/p/log4go``` compatible, so in most cases\ncan be used without any code changes.\n\n#### Breaking change\n\ngo-log was inconsistent with the default Go 'log' package, and log.Fatal calls didn't trigger an os.Exit(1).\n\nThis has been fixed in the current release of go-log, which might break backwards compatibility.\n\nYou can disable the fix by setting ExitOnFatal to false, e.g.\n\n    log.Logger().ExitOnFatal = false\n\n### Getting started\n\nInstall go-log:\n\n```\ngo get github.com/ian-kent/go-log/log\n```\n\nUse the logger in your application:\n\n```\nimport(\n  \"github.com/ian-kent/go-log/log\"\n)\n\n// Pass a log message and arguments directly\nlog.Debug(\"Example log message: %s\", \"example arg\")\n\n// Pass a function which returns a log message and arguments\nlog.Debug(func(){[]interface{}{\"Example log message: %s\", \"example arg\"}})\nlog.Debug(func(i ...interface{}){[]interface{}{\"Example log message: %s\", \"example arg\"}})\n```\n\nYou can also get the logger instance:\n```\nlogger := log.Logger()\nlogger.Debug(\"Yey!\")\n```\n\nOr get a named logger instance:\n\n```\nlogger := log.Logger(\"foo.bar\")\n```\n\n### Log levels\n\nThe default log level is DEBUG.\n\nTo get the current log level:\n\n```\nlevel := logger.Level()\n```\n\nOr to set the log level:\n\n```\n// From a LogLevel\nlogger.SetLevel(levels.TRACE)\n\n// From a string\nlogger.SetLevel(log.Stol(\"TRACE\"))\n```\n\n### Log appenders\n\nThe default log appender is ```appenders.Console()```, which logs\nthe raw message to STDOUT.\n\nTo get the current log appender:\n\n```\nappender := logger.Appender()\n```\n\nIf the appender is ```nil```, the parent loggers appender will be used\ninstead.\n\nIf the appender eventually resolves to ```nil```, log data will be\nsilently dropped.\n\nYou can set the log appender:\n\n```\nlogger.SetAppender(appenders.Console())\n```\n\n#### Rolling file appender\n\nSimilar to log4j's rolling file appender, you can use\n\n```\n// Append to (or create) file\nlogger.SetAppender(appenders.RollingFile(\"filename.log\", true))\n\n// Truncate (or create) file\nlogger.SetAppender(appenders.RollingFile(\"filename.log\", false))\n```\n\nYou can also control the number of log files which are kept:\n```\nr := appenders.RollingFile(\"filename.log\", true)\nr.MaxBackupIndex = 2 // filename.log, filename.log.1, filename.log.2\n```\n\nAnd the maximum log file size (in bytes):\n```\nr := appenders.RollingFile(\"filename.log\", true)\nr.MaxFileSize = 1024 // 1KB, defaults to 100MB\n```\n\n#### Fluentd appender\n\nThe fluentd appender lets you write log data directly to fluentd:\n\n```\nlogger.SetAppender(appenders.Fluentd(fluent.Config{}))\n```\n\nIt uses ```github.com/t-k/fluent-logger-golang```.\n\nThe tag is currently fixed to 'go-log', and the data structure sent\nto fluentd is simple:\n\n```\n{\n  message: \"\u003coutput from layout\u003e\"\n}\n\n```\n\n### Layouts\n\nEach appender has its own layout. This allows the log data to be transformed\nas it is written to the appender.\n\nThe default layout is ```layout.Basic()```, which passes the log message\nand its arguments through ```fmt.Sprintf```.\n\nTo get the current log appender layout:\n```\nappender := logger.Appender()\nlayout := appender.Layout()\n```\n\nTo set the log appender layout:\n```\nappender.SetLayout(layout.Basic())\n```\n\nYou can also use ```layout.Pattern(pattern string)```, which accepts a\npattern format similar to log4j:\n\n| Code | Description\n| ---- | -----------\n| %c   | The package the log statement is in\n| %C   | Currently also the package the log statement is in\n| %d   | The current date/time, using ```time.Now().String()```\n| %F   | The filename the log statement is in\n| %l   | The location of the log statement, e.g. ```package/somefile.go:12```\n| %L   | The line number the log statement is on\n| %m   | The log message and its arguments formatted with ```fmt.Sprintf```\n| %n   | A new-line character\n| %p   | Priority - the log level\n| %r   | ms since logger was created\n\n### Logger inheritance\n\nLoggers are namespaced with a ```.```, following similar rules to Log4j.\n\nIf you create a logger named ```foo```, it will automatically inherit the\nlog settings (levels and appender) of the root logger.\n\nIf you then create a logger named ```foo.bar```, it will inherit the log\nsettings of ```foo```, which in turn inherits the log settings from the\nroot logger.\n\nYou can break this by setting the log level or setting an appender on\na child logger, e.g.:\n\n```\nlogger := log.Logger(\"foo.bar\")\nlogger.SetLevel(levels.TRACE)\nlogger.SetAppender(appenders.Console())\n```\n\nIf you then created a logger named ```foo.bar.qux```, it would inherit\nthe trace level and console appender of the ```foo.bar``` logger.\n\n### Roadmap\n\n* log4j configuration support\n  * .properties\n  * .xml\n  * .json\n* layouts\n  * fixmes/todos in pattern layout\n* appenders\n  * add socket appender\n  * fixmes/todos and tests for fluentd appender\n* optimise logger creation\n  * collapse loggers when parent namespace is unused\n  * reorganise loggers when new child tree is created\n* add godoc documentation\n\n### Contributing\n\nBefore submitting a pull request:\n\n  * Format your code: ```go fmt ./...```\n  * Make sure tests pass: ```go test ./...```\n\n### Licence\n\nCopyright ©‎ 2014, Ian Kent (http://www.iankent.eu).\n\nReleased under MIT license, see [LICENSE](LICENSE.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fian-kent%2Fgo-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fian-kent%2Fgo-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fian-kent%2Fgo-log/lists"}