{"id":13413319,"url":"https://github.com/go-ozzo/ozzo-log","last_synced_at":"2025-06-11T04:16:34.931Z","repository":{"id":55144607,"uuid":"44776974","full_name":"go-ozzo/ozzo-log","owner":"go-ozzo","description":"A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets.","archived":false,"fork":false,"pushed_at":"2021-01-07T10:03:10.000Z","size":49,"stargazers_count":122,"open_issues_count":9,"forks_count":31,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-25T05:23:06.446Z","etag":null,"topics":[],"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/go-ozzo.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":"2015-10-22T22:29:02.000Z","updated_at":"2024-05-17T16:43:57.000Z","dependencies_parsed_at":"2022-08-14T13:20:47.452Z","dependency_job_id":null,"html_url":"https://github.com/go-ozzo/ozzo-log","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/go-ozzo%2Fozzo-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-ozzo%2Fozzo-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-ozzo%2Fozzo-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-ozzo%2Fozzo-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-ozzo","download_url":"https://codeload.github.com/go-ozzo/ozzo-log/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-ozzo%2Fozzo-log/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259197980,"owners_count":22820156,"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:37.616Z","updated_at":"2025-06-11T04:16:34.904Z","avatar_url":"https://github.com/go-ozzo.png","language":"Go","funding_links":[],"categories":["Logging","日志记录","Relational Databases","日志","\u003cspan id=\"日志-logging\"\u003e日志 Logging\u003c/span\u003e","Logging 日志库"],"sub_categories":["Search and Analytic Databases","检索及分析资料库","Advanced Console UIs","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","SQL 查询语句构建库","交流"],"readme":"# ozzo-log\n\n[![GoDoc](https://godoc.org/github.com/go-ozzo/ozzo-log?status.png)](http://godoc.org/github.com/go-ozzo/ozzo-log)\n[![Build Status](https://travis-ci.org/go-ozzo/ozzo-log.svg?branch=master)](https://travis-ci.org/go-ozzo/ozzo-log)\n[![Coverage Status](https://coveralls.io/repos/github/go-ozzo/ozzo-log/badge.svg?branch=master)](https://coveralls.io/github/go-ozzo/ozzo-log?branch=master)\n[![Go Report](https://goreportcard.com/badge/github.com/go-ozzo/ozzo-log)](https://goreportcard.com/report/github.com/go-ozzo/ozzo-log)\n\n## Other languages\n\n[简体中文](/docs/README-zh-CN.md) [Русский](/docs/README-ru.md)\n\n## Description\n\nozzo-log is a Go package providing enhanced logging support for Go programs. It has the following features:\n\n* High performance through asynchronous logging;\n* Recording message severity levels;\n* Recording message categories;\n* Recording message call stacks;\n* Filtering via severity levels and categories;\n* Customizable message format;\n* Configurable and pluggable message handling through log targets;\n* Included console, file, network, and email log targets.\n\n## Requirements\n\nGo 1.2 or above.\n\n## Installation\n\nRun the following command to install the package:\n\n```\ngo get github.com/go-ozzo/ozzo-log\n```\n\n## Getting Started\n\nThe following code snippet shows how you can use this package.\n\n```go\npackage main\n\nimport (\n\t\"github.com/go-ozzo/ozzo-log\"\n)\n\nfunc main() {\n    // creates the root logger\n\tlogger := log.NewLogger()\n\n\t// adds a console target and a file target\n\tt1 := log.NewConsoleTarget()\n\tt2 := log.NewFileTarget()\n\tt2.FileName = \"app.log\"\n\tt2.MaxLevel = log.LevelError\n\tlogger.Targets = append(logger.Targets, t1, t2)\n\n\tlogger.Open()\n\tdefer logger.Close()\n\n\t// calls log methods to log various log messages\n\tlogger.Error(\"plain text error\")\n\tlogger.Error(\"error with format: %v\", true)\n\tlogger.Debug(\"some debug info\")\n\n\t// customizes log category\n\tl := logger.GetLogger(\"app.services\")\n\tl.Info(\"some info\")\n\tl.Warning(\"some warning\")\n\n\t...\n}\n```\n\n## Loggers and Targets\n\nA logger provides various log methods that can be called by application code\nto record messages of various severity levels.\n\nA target filters log messages by their severity levels and message categories\nand processes the filtered messages in various ways, such as saving them in files,\nsending them in emails, etc.\n\nA logger can be equipped with multiple targets each with different filtering conditions.\n\nThe following targets are included in the ozzo-log package.\n\n* `ConsoleTarget`: displays filtered messages to console window\n* `FileTarget`: saves filtered messages in a file (supporting file rotating)\n* `NetworkTarget`: sends filtered messages to an address on a network\n* `MailTarget`: sends filtered messages in emails\n\nYou can create a logger, configure its targets, and start to use logger with the following code:\n\n```go\n// creates the root logger\nlogger := log.NewLogger()\nlogger.Targets = append(logger.Targets, target1, target2, ...)\nlogger.Open()\n...calling log methods...\nlogger.Close()\n```\n\n## Severity Levels\n\nYou can log a message of a particular severity level (following the RFC5424 standard)\nby calling one of the following methods of the `Logger` struct:\n\n* `Emergency()`: the system is unusable.\n* `Alert()`: action must be taken immediately.\n* `Critical()`: critical conditions.\n* `Error()`: error conditions.\n* `Warning()`: warning conditions.\n* `Notice()`: normal but significant conditions.\n* `Info()`: informational purpose.\n* `Debug()`: debugging purpose.\n\n## Message Categories\n\nEach log message is associated with a category which can be used to group messages.\nFor example, you may use the same category for messages logged by the same Go package.\nThis will allow you to selectively send messages to different targets.\n\nWhen you call `log.NewLogger()`, a root logger is returned which logs messages using\nthe category named as `app`. To log messages with a different category, call the `GetLogger()`\nmethod of the root logger or a parent logger to get a child logger and then call its\nlog methods:\n\n```go\nlogger := log.NewLogger()\n// the message is of category \"app\"\nlogger.Error(\"...\")\n\nl1 := logger.GetLogger(\"system\")\n// the message is of category \"system\"\nl1.Error(\"...\")\n\nl2 := l1.GetLogger(\"app.models\")\n// the message is of category \"app.models\"\nl2.Error(\"...\")\n```\n\n## Message Formatting\n\nBy default, each log message takes this format when being sent to different targets:\n\n```\n2015-10-22T08:39:28-04:00 [Error][app.models] something is wrong\n...call stack (if enabled)...\n```\n\nYou may customize the message format by specifying your own message formatter when calling\n`Logger.GetLogger()`. For example,\n\n```go\nlogger := log.NewLogger()\nlogger = logger.GetLogger(\"app\", func (l *Logger, e *Entry) string {\n    return fmt.Sprintf(\"%v [%v][%v] %v%v\", e.Time.Format(time.RFC822Z), e.Level, e.Category, e.Message, e.CallStack)\n})\n```\n\n\n## Logging Call Stacks\n\nBy setting `Logger.CallStackDepth` as a positive number, it is possible to record call stack information for\neach log method call. You may further configure `Logger.CallStackFilter` so that only call stack frames containing\nthe specified substring will be recorded. For example,\n\n```go\nlogger := log.NewLogger()\n// record call stacks containing \"myapp/src\" up to 5 frames per log message\nlogger.CallStackDepth = 5\nlogger.CallStackFilter = \"myapp/src\"\n```\n\n\n## Message Filtering\n\nBy default, messages of *all* severity levels will be recorded. You may customize\n`Logger.MaxLevel` to change this behavior. For example,\n\n```go\nlogger := log.NewLogger()\n// only record messages between Emergency and Warning levels\nlogger.MaxLevel = log.LevelWarning\n```\n\nBesides filtering messages at the logger level, a finer grained message filtering can be done\nat target level. For each target, you can specify its `MaxLevel` similar to that with the logger;\nyou can also specify which categories of the messages the target should handle. For example,\n\n```go\ntarget := log.NewConsoleTarget()\n// handle messages between Emergency and Info levels\ntarget.MaxLevel = log.LevelInfo\n// handle messages of categories which start with \"system.db.\" or \"app.\"\ntarget.Categories = []string{\"system.db.*\", \"app.*\"}\n```\n\n## Configuring Logger\n\nWhen an application is deployed for production, a common need is to allow changing\nthe logging configuration of the application without recompiling its source code.\nozzo-log is designed with this in mind.\n\nFor example, you can use a JSON file to specify how the application and its\nlogger should be configured:\n\n```\n{\n    \"Logger\": {\n        \"Targets\": [\n            {\n                \"type\": \"ConsoleTarget\",\n            },\n            {\n                \"type\": \"FileTarget\",\n                \"FileName\": \"app.log\",\n                \"MaxLevel\": 4   // Warning or above\n            }\n        ]\n    }\n}\n```\n\nAssuming the JSON file is `app.json`, in your application code you can use the `ozzo-config` package\nto load the JSON file and configure the logger used by the application:\n\n```go\npackage main\n\nimport (\n\t\"github.com/go-ozzo/ozzo-config\"\n    \"github.com/go-ozzo/ozzo-log\"\n)\n\nfunc main() {\n    c := config.New()\n    c.Load(\"app.json\")\n    // register the target types to allow configuring Logger.Targets.\n    c.Register(\"ConsoleTarget\", log.NewConsoleTarget)\n    c.Register(\"FileTarget\", log.NewFileTarget)\n\n    logger := log.NewLogger()\n    if err := c.Configure(logger, \"Logger\"); err != nil {\n        panic(err)\n    }\n}\n```\n\nTo change the logger configuration, simply modify the JSON file without\nrecompiling the Go source files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-ozzo%2Fozzo-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-ozzo%2Fozzo-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-ozzo%2Fozzo-log/lists"}