{"id":27881840,"url":"https://github.com/src-d/go-log","last_synced_at":"2025-05-05T05:05:39.106Z","repository":{"id":57484827,"uuid":"130706708","full_name":"src-d/go-log","owner":"src-d","description":" Log is a generic logging library based on logrus","archived":false,"fork":false,"pushed_at":"2019-10-23T17:47:01.000Z","size":44,"stargazers_count":11,"open_issues_count":4,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-05T05:05:33.657Z","etag":null,"topics":["golang","logging"],"latest_commit_sha":null,"homepage":"https://godoc.org/gopkg.in/src-d/go-log.v1","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/src-d.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":"2018-04-23T14:11:12.000Z","updated_at":"2019-10-07T22:49:03.000Z","dependencies_parsed_at":"2022-08-26T11:10:36.867Z","dependency_job_id":null,"html_url":"https://github.com/src-d/go-log","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/src-d%2Fgo-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/src-d%2Fgo-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/src-d%2Fgo-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/src-d%2Fgo-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/src-d","download_url":"https://codeload.github.com/src-d/go-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252442486,"owners_count":21748451,"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","logging"],"created_at":"2025-05-05T05:05:38.528Z","updated_at":"2025-05-05T05:05:39.094Z","avatar_url":"https://github.com/src-d.png","language":"Go","readme":"# go-log [![GoDoc](https://godoc.org/gopkg.in/src-d/go-log.v1?status.svg)](https://godoc.org/github.com/src-d/go-log) [![Build Status](https://travis-ci.org/src-d/go-log.svg)](https://travis-ci.org/src-d/go-log) [![Build status](https://ci.appveyor.com/api/projects/status/15cdr1nk890qpk7g?svg=true)](https://ci.appveyor.com/project/mcuadros/go-log) [![codecov.io](https://codecov.io/github/src-d/go-log/coverage.svg)](https://codecov.io/github/src-d/go-log) [![Go Report Card](https://goreportcard.com/badge/github.com/src-d/go-log)](https://goreportcard.com/report/github.com/src-d/go-log)\n\nLog is a generic logging library based on logrus (this may change in the\nfuture), that minimize the exposure of src-d projects to logrus or any other\nlogging library, as well defines the standard for configuration and usage of the\nlogging libraries in the organization.\n\nInstallation\n------------\n\nThe recommended way to install *go-log* is:\n\n```\ngo get -u gopkg.in/src-d/go-log.v1/...\n```\n\nConfiguration\n-------------\n\nThe configuration should be done always using environment variables. The list\nof available variables is:\n\n- `LOG_LEVEL`: Reporting level, values are \"info\", \"debug\", \"warning\" or \"error\".\n- `LOG_FORMAT`: Format of the log lines, values are \"text\", \"json\" or \"fluentd\", by default \"text\" is used. unless a terminal can't be detected, in this case, \"json\" is used instead.\n- `LOG_FIELDS`: Fields in JSON or fluentd format to be included in all the loggers.\n- `LOG_FORCE_FORMAT`: If true the fact of being in a terminal or not is ignored.\n\n\u003e By default the logging is disabled if go-log is being executed in tests.\n\nUsage\n-----\n\n### Basic usage\n\nThe most basic form of logging is made using the `Infof`, `Debugf`, `Warningf`\nand `Errorf` functions at the top level of the packages.\n\n```go\nlog.Infof(\"The answer to life, the universe and everything is %d\", 42)\n// INFO The answer to life, the universe and everything is 42\n```\n\nThese functions use the `DefaultLogger` a logger lazy instanced when this method\nare called. This logger reads the configuration from the environment variables.\n\n### Logger instantiation\n\nIf you prefer to keep a reference to the `Logger`, in your packages or structs\nto have more control over it (for example for tests). A default `Logger`, can\nbe instantiated using the `New` method.\n\n```go\nlogger := log.New(nil)\nlogger.Infof(\"The answer to life, the universe and everything is %d\", 42)\n// INFO The answer to life, the universe and everything is 42\n```\n\nAlso, a new `Logger` can be created from other `Logger` in order to have\ncontextual information, using the method `Logger.New`\n\n```go\nlogger := log.New(nil)\n\nauthorLogger := logger.New(log.Field{\"author\": \"Douglas Adams\"})\nbookLogger.Infof(\"The Hitchhiker's Guide to the Galaxy\")\nbookLogger.Infof(\"Life, the Universe and Everything\")\n// INFO The Hitchhiker's Guide to the Galaxy author=Douglas Adams\n// INFO Life, the Universe and Everything author=Douglas Adams\n```\n\nOr if you just want to add contextual information `Logger.New` to one log line\nyou can use the `Logger.With` method.\n\n```go\nlogger := log.New(nil)\n\nauthorLogger := logger.New(log.Field{\"author\": \"Douglas Adams\"})\nbookLogger.With(log.Fields{\"isbn\": \"0-330-25864-8\"}).Infof(\"The Hitchhiker's Guide to the Galaxy\")\nbookLogger.With(log.Fields{\"isbn\": \"0-345-39182-9\"}).Infof(\"Life, the Universe and Everything\")\n// INFO The Hitchhiker's Guide to the Galaxy author=Douglas Adams isbn=0-330-25864-8\n// INFO Life, the Universe and Everything author=Douglas Adams isbn=0-345-39182-9\n```\n\n### Logging errors\n\nIn `go-log` the errors are logged using the function `Logger.Errorf`:\n\n```go\nlogger, _ := log.New()\n\n_, err := http.Get(\"https://en.wikipedia.org/wiki/Douglas_Adams\")\nif err != nil {\n    logger.Errorf(err, \"unable to retrieve page\")\n}\n```\n\nLicense\n-------\nApache License Version 2.0, see [LICENSE](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrc-d%2Fgo-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrc-d%2Fgo-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrc-d%2Fgo-log/lists"}