{"id":18439298,"url":"https://github.com/socifi/golog","last_synced_at":"2025-08-21T07:14:33.403Z","repository":{"id":92247095,"uuid":"141973026","full_name":"socifi/golog","owner":"socifi","description":"Fork of https://github.com/apex/log that comply with SOCIFI's standards.","archived":false,"fork":false,"pushed_at":"2019-02-04T13:33:42.000Z","size":113,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-14T16:19:12.246Z","etag":null,"topics":["golang","logging"],"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/socifi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-23T06:45:43.000Z","updated_at":"2019-02-05T21:34:40.000Z","dependencies_parsed_at":"2023-06-08T03:30:33.446Z","dependency_job_id":null,"html_url":"https://github.com/socifi/golog","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/socifi/golog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socifi%2Fgolog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socifi%2Fgolog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socifi%2Fgolog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socifi%2Fgolog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/socifi","download_url":"https://codeload.github.com/socifi/golog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socifi%2Fgolog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271442024,"owners_count":24760352,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["golang","logging"],"created_at":"2024-11-06T06:24:06.884Z","updated_at":"2025-08-21T07:14:33.379Z","avatar_url":"https://github.com/socifi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golog\n\nGolog is palindrome. Palindromes are cool! Like `A Santa at Nasa.` or `Flee to me, remote elf.`\n\nBased on [Apex log](https://github.com/apex/log) with few tweaks. Unless otherwise noted (mainly in `pkg.go`), this package should be thread safe. Just for the record the architecture leaves almost all thread safety on handlers so if you are uncertain, consult the documentation and code of the handlers you use.\n\n## Functionality\n\n### Autogenerated levels\n\nThis package contains python script for automatic log level generation. By default, the script uses log levels that comply with RFC 5424 levels (debug, info, notice, warning, error, critical, alert, emergency) but can be easily tweaked to generate entirely custom level names and level numbers. Just alter the level names and level codes at the top of the file `gen_levels.py` and run it. It will take care about everything else (unless you deleted guideline comments).\n\n### Hooks\n\nThis package allows registering of hooks which will be run on every field in a log entry to check specific things in field name and then apply some function to its content. The rationale behind this is that some pieces of information might be very useful in troubleshooting some problems but you might want to review information sent over network (e.g. logging passwords is very bad practice).\n\n#### What the hooks are good for\n\nThe hooks are useful for many things. The most important use-case is for filtering data passed to logging service. DSN hook will, for example, check if a field name contains `dsn` (case insensitive). If it does the hook will then try to convert DSN interface to string and hide password in this string. This feature is entirely opt-in and might be included by importing module DSN as such:\n\n```golang\nimport(\n\t// ...\n\t\"github.com/socifi/golog\"\n\t_ \"github.com/socifi/golog/hook/dsn\"\n\t// ...\n)\n```\n\n#### How to write a custom hook\n\nThe hook is an interface with two functions. First one is `Check(string) bool` which takes field name as a parameter and returns if the field should be processed or not. The other function is `Sanitize(interface{}) interface{}` which takes a field value and does some processing on it and returns processed interface which will be saved or sent to logging service.\n\nExample implementations of hooks are in folder `hook/`.\n\n\n```golang\npackage hook\n\nimport (\n\t\"github.com/socifi/golog\"\n\t\"strings\"\n)\n\ntype hook struct{}\n\nvar h hook\n\n// Register hook to the mechanism\nfunc init() {\n\tlog.RegisterSanitizeHook(h)\n}\n\nfunc (dsn) Check(s string) bool {\n\t// string.Contains was chosen for simplicity, any logic can be here\n\tif strings.Contains(strings.ToLower(s), \"password\") {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc (dsn) Sanitize(v interface{}) interface{} {\n\t// In case it's impossible to convert to chosen type return original value and do nothing with it\n\ts, ok := v.(string)\n\tif !ok {\n\t\treturn v\n\t}\n\n\t// Again any logic (e.g. regex) can be here, this is for simplicity\n\ts = \"***\"\n\n\treturn s\n}\n```\n\n### Atexit\n\nInspired by [atexit module](github.com/tebeka/atexit) golog also offers the possibility to register a function which will be run on system exit. However this functionality has the same caveat as atexit, the program needs to be closed with any `Exit(code int)` function in this module. This function as well as `AddExitHandler(handler func())` which registers functions to be run on program exit is defined for both module, logger and entry.\n\nA side note: To access local variables use closures:\n\n```golang\n\t// ...\n\ta := \"something\"\n\tlog.AddExitHandler( func() {\n\t\tfmt.Println(a)\n\t})\n\t// ...\n\n\t// End the program\n\tlog.Exit(0)\n```\n\n\n### Simple logger initialization from config json\n\nThere is also initialization script which allows a simple load of configuration needed by the logger. This feature is now limited to JSON and elastic handlers and might be changed in the future to allow better interoperability with e.g. [Viper](https://github.com/spf13/viper). __We, therefore, cannot guarantee any backward compatibility in this module!__\nBut for now the example usage is the following:\n\n```golang\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"github.com/socifi/golog/handlers/init\"\n\t_ \"github.com/socifi/golog/hook/dsn\"\n\t\"io/ioutil\"\n\t\"os\"\n)\n\ntype autoGenerated struct {\n\t/* Your other config here... */\n\tLogging loginit.LogConfig `json:\"logging\"`\n}\n\nfunc main() {\n\traw, err := ioutil.ReadFile(\"./config.json\")\n\tif err != nil {\n\t\tfmt.Println(err.Error())\n\t\tos.Exit(1)\n\t}\n\n\tvar c autoGenerated\n\tjson.Unmarshal(raw, \u0026c)\n\tfmt.Printf(\"%#v\\n\", c)\n\tlogger := loginit.Init(c.Logging)\n\tlogger.WithField(\"dsn\", \"host=localhost port=5432 user=postgres password=postgres dbname=postgres sslmode=disable\").Info(\"trial\")\n}\n```\n\n## Handlers\n\nSome handlers which support a fixed number of log levels only have been discarded and only the following were kept. PR for simple text handler which will be able to process any number of levels is welcome.\n\n- __discard__ – discards all logs\n- __es__ – Elasticsearch handler\n- __init__ – Initialization script\n- __json__ – JSON output handler\n- __kinesis__ – AWS Kinesis handler\n- __level__ – level filter handler\n- __logfmt__ – logfmt plain-text formatter\n- __memory__ – in-memory handler for tests\n- __multi__ – fan-out to multiple handlers\n- __papertrail__ – Papertrail handler\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocifi%2Fgolog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocifi%2Fgolog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocifi%2Fgolog/lists"}