{"id":13413334,"url":"https://github.com/xfxdev/xlog","last_synced_at":"2025-03-14T19:31:52.551Z","repository":{"id":57486674,"uuid":"58146351","full_name":"xfxdev/xlog","owner":"xfxdev","description":"plugin architecture and flexible log system for golang","archived":false,"fork":false,"pushed_at":"2019-01-15T10:17:30.000Z","size":15,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-07-31T20:52:13.413Z","etag":null,"topics":["golang","log","plugin-architecture"],"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/xfxdev.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":"2016-05-05T16:47:45.000Z","updated_at":"2022-09-26T23:24:18.000Z","dependencies_parsed_at":"2022-09-01T20:31:55.148Z","dependency_job_id":null,"html_url":"https://github.com/xfxdev/xlog","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/xfxdev%2Fxlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfxdev%2Fxlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfxdev%2Fxlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfxdev%2Fxlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xfxdev","download_url":"https://codeload.github.com/xfxdev/xlog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243635347,"owners_count":20322925,"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","log","plugin-architecture"],"created_at":"2024-07-30T20:01:38.008Z","updated_at":"2025-03-14T19:31:52.289Z","avatar_url":"https://github.com/xfxdev.png","language":"Go","readme":"# xlog\nplugin architecture and flexible log system for golang\n\n[![Build Status](https://travis-ci.org/xfxdev/xlog.svg?branch=master)](https://travis-ci.org/xfxdev/xlog)\n[![Go Report Card](https://goreportcard.com/badge/github.com/xfxdev/xlog)](https://goreportcard.com/report/github.com/xfxdev/xlog)\n[![GoDoc](https://godoc.org/github.com/xfxdev/xlog?status.svg)](https://godoc.org/github.com/xfxdev/xlog)\n\nInstallation\n================\n~~~\ngo get github.com/xfxdev/xlog\n~~~\n\nUsage\n================\n~~~\nimport (\n    \"github.com/xfxdev/xlog\"\n)\n\nstrLogLevel := \"INFO\"  // also maybe read from config.\nlogLevel, suc := xlog.ParseLevel(strLogLevel)\nif suc == false {\n    // failed to parse log level, will use the default level[INFO] instead.\"\n}\nxlog.SetLevel(logLevel)\n\n// write log to file.\nw2f, err := xlog.NewW2FileListener(\"\")\nif err != nil {\n    xlog.Fatal(err)\n} else {\n    xlog.AddListener(w2f)\n}\n\nxlog.Info(\"server start...\")\nxlog.Debugf(\"ip : %v\", \"127.0.0.1\")\n~~~\n\nFeatures\n================\n###Level logging\n~~~\n// xlog provide 6 logging levels.\nconst (\n\tPanicLevel Level = iota\n\tFatalLevel\n\tErrorLevel\n\tWarnLevel\n\tInfoLevel\n\tDebugLevel\n)\n~~~\n\nyou can call 'SetLevel' to change the log level. All the logs which level \u003c= your set will be output.\nfor example:\n~~~\n// all logs will be output because DEBUG is the max level.\nxlog.SetLevel(xlog.DebugLevel) \n\n// only Panic/Fatal/Error logs will be output because WARN/INFO/DEBUG \u003e ERROR.\nxlog.SetLevel(xlog.ErrorLevel)\n~~~\n\n###Custom Log Layout\nxlog provide a flexible log layout system to custom the style of log output.\nWhat you need to do is just set the layout flags.\n~~~\nxlog.SetLayout('layout flags...')\n~~~\nxlog provide some builtin layout:\n~~~\n//   %y : year\n//   %M : month\n//   %d : day\n//   %h : hour\n//   %m : min\n//   %s : second\n//   %l : log msg\n//   %L : log level\n//   %F : file\t\t\teg: /a/b/c/d.go\n//   %f : short file\teg: d.go\n//   %i : line\n//   %D : %y/%M/%d\n//   %T : %h:%m:%s\n~~~\nYou can use a combination of them, for example:\n~~~\n// this mean every log message will have a '[level] year/month/day hour:min:sec' perfix, eg:\nxlog.SetLayout(\"%L %D %T %l\")\n\n// outputs:\n[INFO] 2016/01/01 13:27:07 net start...\n[WARN] 2016/01/01 13:28:00 ...\n[DEBUG] 2016/01/01 13:28:00 accept...\n\n// add filename and line to log message.\nxlog.SetLayout(\"%L %D %T [%f(%i)] %l\")\n\n// outputs:\n[INFO] 2016/01/01 13:27:07 [test.go:(72)] net start...\n[WARN] 2016/01/01 13:28:00 [test.go:(100)] ...\n[DEBUG] 2016/01/01 13:28:00 [test.go:(128)] accept...\n~~~\nYou can use any form of combination, even meaningless thing, such as more spaces, arbitrary symbols:\n~~~\nxlog.SetLayout(\"hahaha%L | %D   %T [ABC] %l [i'm after hahaha]\")\n\n// outputs:\n// notice the prefix 'hahaha', the spaces in the middle, and the suffix '[i'm after hahaha]'\nhahaha[INFO] | 2017/01/07     14:09:47 [ABC] net start... [i'm after hahaha]\nhahaha[WARN] | 2017/01/07     14:09:47 [ABC] ... [i'm after hahaha]\nhahaha[DEBUG] | 2017/01/07     14:09:47 [ABC] accept... [i'm after hahaha]\n~~~\nNOTICE: If you doesn't call 'SetLayout', xlog will use '%L %D %T %l' by default.\n\n###Output a log to different targets\nxlog use listener system to output the log message.\n~~~\n// A Listener simple typed of io.Writer\ntype Listener io.Writer\n~~~\nA logger can have multiple listeners, xlog have 2 builtin listener, which are os.Stderr and W2FileListener.\nxlog will output log to os.Stderr by default, but you can add W2FileListener to output the log to file.\n~~~\nw2f, err := xlog.NewW2FileListener(\"logfilePath...\")\nif err != nil {\n    xlog.Fatal(err)\n} else {\n    xlog.AddListener(w2f)\n}\n~~~\nIn 'NewW2FileListener' function, xlog will use the 'logfilePath' to create log file,\nso please makesure your path is correct.\n~~~\nos.MkdirAll(filepath.Dir(logfilePath), os.ModePerm)\n~~~\nAlso, you can give a empty path to NewW2FileListener(\"\"), this will create log file by simple rule. for example:\nIf your app current path is 'a/b/c', and your app name is 'testapp'\nThen the log file will be 'a/b/c/log/testapp_2016_01_01.log'\n~~~\nw2f, err := xlog.NewW2FileListener(\"\")  // create log file at : 'a/b/c/log/test_2016_01_01.log'\nif err != nil {\n    xlog.Fatal(err)\n}\nxlog.AddListener(w2f)\n~~~\nYou can create new listener according you need, just implement the io.Writer interface.\n~~~\ntype Writer interface {\n\tWrite(p []byte) (n int, err error)\n}\n~~~\n###Thread safety\nBy default xlog is protected by mutex, so you can output logs in multiple goroutines.\n","funding_links":[],"categories":["Logging","Logging 日志库","\u003cspan id=\"日志-logging\"\u003e日志 Logging\u003c/span\u003e","日志记录","日志","Relational Databases","日誌"],"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%2Fxfxdev%2Fxlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxfxdev%2Fxlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfxdev%2Fxlog/lists"}