{"id":17497078,"url":"https://github.com/ccding/go-logging","last_synced_at":"2025-04-23T01:08:03.697Z","repository":{"id":9696220,"uuid":"11645038","full_name":"ccding/go-logging","owner":"ccding","description":"the logging package for golang","archived":false,"fork":false,"pushed_at":"2019-06-18T17:55:24.000Z","size":155,"stargazers_count":66,"open_issues_count":3,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-23T01:07:58.549Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ccding.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":"2013-07-24T20:53:35.000Z","updated_at":"2023-11-03T20:09:41.000Z","dependencies_parsed_at":"2022-09-26T20:41:06.673Z","dependency_job_id":null,"html_url":"https://github.com/ccding/go-logging","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccding%2Fgo-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccding%2Fgo-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccding%2Fgo-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccding%2Fgo-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccding","download_url":"https://codeload.github.com/ccding/go-logging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250349055,"owners_count":21415914,"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-10-19T15:10:22.120Z","updated_at":"2025-04-23T01:08:03.677Z","avatar_url":"https://github.com/ccding.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-logging\n\n[![Build Status](https://travis-ci.org/ccding/go-logging.svg?branch=master)](https://travis-ci.org/ccding/go-logging)\n[![License](https://img.shields.io/badge/License-Apache%202.0-red.svg)](https://opensource.org/licenses/Apache-2.0)\n[![GoDoc](https://godoc.org/github.com/ccding/go-logging?status.svg)](http://godoc.org/github.com/ccding/go-logging/logging)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ccding/go-logging)](https://goreportcard.com/report/github.com/ccding/go-logging)\n\ngo-logging is a high-performance logging library for golang.\n* Simple: It supports only necessary operations and easy to get started.\n* Fast: Asynchronous logging without runtime-related fields has an extremely\n  low delay of about 800 nano-seconds.\n* Performance in my laptop as follow.\n```bash\nBenchmarkSync      \t  300000\t      4018 ns/op\nBenchmarkAsync     \t  300000\t      4229 ns/op\nBenchmarkBasicSync \t  500000\t      2504 ns/op\nBenchmarkBasicAsync\t 1000000\t      2495 ns/op\nBenchmarkPrintln   \t 1000000\t      1550 ns/op\n```\n\n## Getting Started\n### Installation\nThe step below will download the library source code to\n`${GOPATH}/src/github.com/ccding/go-logging`.\n```bash\ngo get github.com/ccding/go-logging/logging\n```\n\nGiven the source code downloaded, it makes you be able to run the examples,\ntests, and benchmarks.\n```bash\ncd ${GOPATH}/src/github.com/ccding/go-logging/logging\ngo get\ngo run ../example.go\ngo test -v -bench .\n```\n\n### Example\ngo-logging is used like any other Go libraries. You can simply use the library\nin this way.\n```go\nimport \"github.com/ccding/go-logging/logging\"\n```\n\nHere is a simple example.\n```go\npackage main\n\nimport (\n\t\"github.com/ccding/go-logging/logging\"\n)\n\nfunc main() {\n\tlogger, _ := logging.SimpleLogger(\"main\")\n\tlogger.Error(\"this is a test from error\")\n\tlogger.Destroy()\n}\n```\n\n### Configuration\n#### Construction Functions\nIt has the following functions to create a logger.\n```go\n// with BasicFormat and writing to stdout\nSimpleLogger(name string) (*Logger, error)\n// with BasicFormat and writing to DefaultFileName\nBasicLogger(name string) (*Logger, error)\n// with RichFormatand writing to DefaultFileName\nRichLogger(name string) (*Logger, error)\n// with detailed configuration and writing to file\nFileLogger(name string, level Level, format string, timeFormat string, file string, sync bool) (*Logger, error)\n// with detailed configuration and writing to a writer\nWriterLogger(name string, level Level, format string, timeFormat string, out io.Writer, sync bool) (*Logger, error)\n// read configurations from a config file\nConfigLogger(filename string) (*Logger, error)\n```\nThe meanings of these fields are\n```go\nname           string        // logger name\nlevel          Level         // record level higher than this will be printed\nformat         string        // format configuration\ntimeFormat     string        // format for time\nfile           string        // file name for logging\nout            io.Writer     // writer for logging\nsync           bool          // use sync or async way to record logs\n```\nThe detailed description of these fields will be presented later.\n\n#### Logging Functions\nIt supports the following functions for logging. All of these functions are\nthread-safe.\n```go\n(*Logger) Logf(level Level, format string, v ...interface{})\n(*Logger) Log(level Level, v ...interface{})\n(*Logger) Criticalf(format string, v ...interface{})\n(*Logger) Critical(v ...interface{})\n(*Logger) Fatalf(format string, v ...interface{})\n(*Logger) Fatal(v ...interface{})\n(*Logger) Errorf(format string, v ...interface{})\n(*Logger) Error(v ...interface{})\n(*Logger) Warningf(format string, v ...interface{})\n(*Logger) Warning(v ...interface{})\n(*Logger) Warnf(format string, v ...interface{})\n(*Logger) Warn(v ...interface{})\n(*Logger) Infof(format string, v ...interface{})\n(*Logger) Info(v ...interface{})\n(*Logger) Debugf(format string, v ...interface{})\n(*Logger) Debug(v ...interface{})\n(*Logger) Notsetf(format string, v ...interface{})\n(*Logger) Notset(v ...interface{})\n```\n\n#### Logger Operations\nThe logger supports the following operations.  In these functions, `SetWriter`\nand `Destroy` are not thread-safe, while others are. All these functions are\nrunning in a synchronous way.\n```go\n// Getter functions\n(*Logger) Name() string                    // get name\n(*Logger) TimeFormat() string              // get time format\n(*Logger) Level() Level                    // get level  [this function is thread safe]\n(*Logger) RecordFormat() string            // get the first part of the format\n(*Logger) RecordArgs() []string            // get the second part of the format\n(*Logger) Writer() io.Writer               // get writer\n(*Logger) Sync() bool                      // get sync or async\n\n// Setter functions\n(*Logger) SetLevel(level Level)            // set level  [this function is thread safe]\n(*Logger) SetWriter(out ...io.Writer)      // set multiple writers\n\n// Other functions\n(*Logger) Flush()             // flush the writer\n(*Logger) Destroy()           // destroy the logger\n```\n\n#### Fields Description\n\n##### Name\nName field is a string, which can be written to the logging and used to\nseparate multiple loggers. It allows two logger having the same name.  There\nis not any default value for name.\n\n##### Logging Levels\nThere are these levels in logging.\n```go\nCRITICAL     50\nFATAL        CRITICAL\nERROR        40\nWARNING      30\nWARN         WARNING\nINFO         20\nDEBUG        10\nNOTSET       0\n```\n\n##### Record Format\nThe record format is described by a string, which has two parts separated by\n`\\n`. The first part describes the format of the log, and the second part\nlists all the fields to be shown in the log. In other word, the first part is\nthe first parameter `format` of `fmt.Printf(format string, v ...interface{})`,\nand the second part describes the second parameter `v` of it. It is not\nallowed to have `\\n` in the first part.  The fields in the second part are\nseparated by comma `,`, while extra blank spaces are allowed.  An example of\nthe format string is\n```go\nconst BasicFormat = \"%s [%6s] %30s - %s\\n name,levelname,time,message\"\n```\nwhich is the pre-defined `BasicFormat` used by `BasicLogger()` and\n`SimpleLogger()`.\n\nIt supports the following fields for the second part of the format.\n```go\n\"name\"          string     %s      // name of the logger\n\"seqid\"         uint64     %d      // sequence number\n\"levelno\"       int32      %d      // level number\n\"levelname\"     string     %s      // level name\n\"created\"       int64      %d      // starting time of the logger\n\"nsecs\"         int64      %d      // nanosecond of the starting time\n\"time\"          string     %s      // record created time\n\"timestamp\"     int64      %d      // timestamp of record\n\"rtime\"         int64      %d      // relative time since started\n\"filename\"      string     %s      // source filename of the caller\n\"pathname\"      string     %s      // filename with path\n\"module\"        string     %s      // executable filename\n\"lineno\"        int        %d      // line number in source code\n\"funcname\"      string     %s      // function name of the caller\n\"process\"       int        %d      // process id\n\"message\"       string     %s      // logger message\n```\nThe following runtime-related fields is extremely expensive and slow, please\nbe careful when using them.\n```go\n\"filename\"      string     %s      // source filename of the caller\n\"pathname\"      string     %s      // filename with path\n\"lineno\"        int        %d      // line number in source code\n\"funcname\"      string     %s      // function name of the caller\n```\n\nThere are a few pre-defined values for record format.\n```go\nBasicFormat = \"%s [%6s] %30s - %s\\n name,levelname,time,message\"\nRichFormat  = \"%s [%6s] %d %30s - %d - %s:%s:%d - %s\\n name, levelname, seqid, time, filename, funcname, lineno, message\"\n```\n\n##### Time Format\nWe use the same time format as golang.  The default time format is\n```go\nDefaultTimeFormat     = \"2006-01-02 15:04:05.999999999\" // default time format\n```\n\n##### File Name, Writer, and Sync\nThe meaning of these fields are obvious. Filename is used to create writer.\nWe also allow the user create a writer by herself and pass it to the logger.\nSync describes whether the user would like to use synchronous or asynchronous\nmethod to write logs. `true` value means synchronous method, and `false` value\nmeans asynchronous way.  We suggest you use asynchronous way because it causes\nextremely low extra delay by the logging functions.\n\n## Contributors\nIn alphabetical order\n* Cong Ding ([ccding][ccding])\n* Xiang Li ([xiang90][xiang90])\n* Zifei Tong ([5kg][5kg])\n\n[ccding]: //github.com/ccding\n[xiang90]: //github.com/xiang90\n[5kg]: //github.com/5kg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccding%2Fgo-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccding%2Fgo-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccding%2Fgo-logging/lists"}