{"id":38798028,"url":"https://github.com/nohupped/glog","last_synced_at":"2026-01-17T12:44:49.053Z","repository":{"id":57500265,"uuid":"83832267","full_name":"nohupped/glog","owner":"nohupped","description":"Go's modified built in log package, with an option to set filter based on loglevel.","archived":false,"fork":false,"pushed_at":"2020-01-04T12:57:14.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T07:48:55.748Z","etag":null,"topics":["go","golang","logger","logging","logging-library","loglevel"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nohupped.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":"2017-03-03T19:10:35.000Z","updated_at":"2020-01-04T12:18:09.000Z","dependencies_parsed_at":"2022-09-06T23:21:20.381Z","dependency_job_id":null,"html_url":"https://github.com/nohupped/glog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nohupped/glog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohupped%2Fglog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohupped%2Fglog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohupped%2Fglog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohupped%2Fglog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nohupped","download_url":"https://codeload.github.com/nohupped/glog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohupped%2Fglog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28508552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T11:50:55.898Z","status":"ssl_error","status_checked_at":"2026-01-17T11:50:55.569Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["go","golang","logger","logging","logging-library","loglevel"],"created_at":"2026-01-17T12:44:48.959Z","updated_at":"2026-01-17T12:44:49.023Z","avatar_url":"https://github.com/nohupped.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# glog [![Build Status](https://travis-ci.org/nohupped/glog.svg?branch=master)](https://travis-ci.org/nohupped/glog)\n\nGo's modified log package with an option to set a loglevel, which will filter the output of logs based on that.\n(This is a lame attempt to modify GO's original [`log` package](https://github.com/golang/go/tree/master/src/log) (version 1.6.2)), and the logic borrowed from [Sirupsen](https://github.com/Sirupsen/logrus) package.\n\n## Why\n\nI was trying to find a way to log `filename` and `line number` using logrus for obvious debugging purpose, but I failed to get a workaround. I am not using advanced features of `logrus` like `SetFormatter` or `hooks`. `Go`'s native `log` package already provides a feature to log filename and line numbers but it lacks setting a loglevel for filtering logs. I just borrowed and incorporated the idea of using a `loglevel`.\nNewly added methods for `*Logger` like `(Error|Warn|Info|Debug)ln(), (Error|Warn|Info|Debug)f() and (Error|Warn|Info|Debug)()` will only output logs based on the configured loglevel with the helper function `SetLogLevel()`. Accepted log levels are `ErrorLevel, WarnLevel, InfoLevel and DebugLevel` which are of values `int 0, 1, 2, 3` respectively.\n\nDefault value of `loglevel` at the time of initing the `*Logger` is set to the lowest level, which is `ErrorLevel`.\n\n## Breaking change because of using pointer to loglevel\n\nUse\n\n```bash\nrequire github.com/nohupped/glog v0.0.0-20200102070319-ef78151f855d\n```\n\nin the go.mod file to continue using the older version that uses `int` as `loglevel` instead of `*uint`.\n\n* why? To have the convenience of using this logger in `init()` functions and have a global variable that can be modified without calling the `SetStandardLogLevel` or similar functions in every importing sub-packages.\n\nEg: Package `foo/blah`\n\n```golang\npackage blah\nimport (\n     // \"flag\"\n    log \"github.com/nohupped/glog\"\n)\n\n// Loglevel is the logging handler\nvar Loglevel *uint\n\nfunc init() {\n    // loglevel := flag.Uint(\"loglevel\", uint(glog.InfoLevel), \"Loglevel.\")\n    // flag.Parse()\n    // Don't do the above 2 lines in init functions. This will mess with go's testing because of https://github.com/golang/go/issues/33774.\n    // flag.Parse() and init() functions doesn't go well.\n    if Loglevel == nil {\n        l := log.ErrorLevel\n        Loglevel = \u0026l\n    }\n    log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)\n    log.SetStandardLogLevel(Loglevel)\n    log.Infof(\"Setting loglevel to %d\", log.InfoLevel)\n}\n\n```\n\nand in package foo,\n\n```golang\npackage main\n\nimport(\n    \"foo/blah\"\n)\nfunc main(){\n    loglevel := flag.Uint(\"loglevel\", log.InfoLevel, \"Loglevel.\")\n    flag.Parse()\n    *blah.Loglevel = *loglevel // Dereference and modify the pointer value to update the loglevel globally on all the packages that imports foo/blah.\n}\n```\n\nNow, for another sub-package `foo/extreme_computation`,\n\n```golang\npackage extreme_computation\nimport(\n    _ \"foo/blah\"\n    log \"github.com/nohupped/glog\"\n)\n\nfunc PvsNP() {\n\n}\n\n```\n\nit will see the updated loglevel from the `main` although the initial loglevel was set in `blah`, and this is because of the `var Loglevel *uint`\n\n### Reference when setting loglevel\n\n`logger.SetLogLevel(log.ErrorLevel)` will log only Errors using the method `log.Error*()`. Any calls to `log.Warn*()`, `log.Info*()` and `log.Debug*()` will not be logged unless the `loglevel` is changed.\n\n`logger.SetLogLevel(log.WarnLevel)` will log Errors and Warnings. Rest are not logged.\n\n`logger.SetLogLevel(log.InfoLevel)` will log Errors, Warnings and Info. Rest are not logged.\n\n`logger.SetLogLevel(log.DebugLevel)` will log Errors, Warnings, Info and Debug.\n\nNote: To disable logging line numbers and file names, set the logger's flag similar to `logger := log.New(\u0026buf, \"logger: \", log.Ldate)` instead of `log.Lshortfile` or similar flags.\n\n#### Example\n\n```golang\npackage main\n\nimport (\n    \"bytes\"\n    \"fmt\"\n    log \"github.com/nohupped/glog\"\n)\n\nfunc main() {\n    var buf bytes.Buffer\n    logger := log.New(\u0026buf, \"logger: \", log.Lshortfile)\n    // Below two lines to set logging to file\n    //file, _ := os.OpenFile(\"/tmp/testlog.log\", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)\n    //logger.SetOutput(file)\n    strfn := \"Errorf()!\"\n    logger.Errorf(\"Hello, this is %d Error from %s\", 1, strfn)\n    logger.Error(\"Hello, this is 1 Error from Error()!\")\n    logger.Warnln(\"Hello, This is from Warnln!\") // This will not print because the default loglevel when initiating logger is set to ErrorLevel.\n    il := log.InfoLevel\n    logger.SetLogLevel(\u0026iL)\n    logger.Errorln(\"Hello, This is Error from Errorln!\")\n    logger.Warnln(\"Hello, This is Warn from Warnln!\")\n    logger.Infoln(\"Hello, This is Info from Infoln!\")\n    logger.Debugln(\"Hello, This is Debug from Debugln!\") // This will not print because loglevel is set to InfoLevel\n    dl := log.DebugLevel\n    log.SetStandardLogLevel(\u0026dl) // set std loglevel. This will NOT set the *Logger struct's loglevel.\n    log.SetFlags(log.Lshortfile) // set flags to log. This will add short filename and line number.\n    log.Debugf(\"This is from %s\", strfn)\n    log.Printf(\"%d error from %s\", 1, \"Error function\")\n    log.Warnf(\"%d error from %s\", 1, \"Error function\")\n    fmt.Println(\u0026buf)\n\n    fmt.Print(\u0026buf)\n\n    // Output:\n    // logger: main.go:19: ERROR: Hello, this is 1 Error from Errorf()!\n    // logger: main.go:20: ERROR: Hello, this is 1 Error from Error()!\n    // logger: main.go:23: ERROR: Hello, This is Error from Errorln!\n    // logger: main.go:24: WARN: Hello, This is Warn from Warnln!\n    // logger: main.go:25: INFO: Hello, This is Info from Infoln!\n\n```\n`* Line numbers may vary.`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnohupped%2Fglog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnohupped%2Fglog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnohupped%2Fglog/lists"}