{"id":25174751,"url":"https://github.com/aletheia7/sd","last_synced_at":"2025-05-06T21:06:29.030Z","repository":{"id":19834302,"uuid":"23095654","full_name":"aletheia7/sd","owner":"aletheia7","description":"Go package that writes to the systemd journal","archived":false,"fork":false,"pushed_at":"2022-03-18T23:40:12.000Z","size":388,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T21:06:17.548Z","etag":null,"topics":["cgo","go","journal","journalctl","logging","systemd","systemd-journal","systemd-journald"],"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/aletheia7.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":"2014-08-19T03:35:04.000Z","updated_at":"2024-10-28T01:28:29.000Z","dependencies_parsed_at":"2022-08-25T21:23:47.559Z","dependency_job_id":null,"html_url":"https://github.com/aletheia7/sd","commit_stats":null,"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aletheia7%2Fsd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aletheia7%2Fsd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aletheia7%2Fsd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aletheia7%2Fsd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aletheia7","download_url":"https://codeload.github.com/aletheia7/sd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252769397,"owners_count":21801377,"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":["cgo","go","journal","journalctl","logging","systemd","systemd-journal","systemd-journald"],"created_at":"2025-02-09T12:21:00.190Z","updated_at":"2025-05-06T21:06:29.001Z","avatar_url":"https://github.com/aletheia7.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/aletheia7/sd) \n\n#### Install \n```bash\ngo get github.com/aletheia7/sd\ncd \u003csd location\u003e\ngo test -v\n```\nOlder systemd versions used libsystemd-journal. Change the following line if\nyou have libsystemd-journal:\n\n```go\n// #cgo pkg-config: --cflags --libs libsystemd\n```\nto\n```go\n// #cgo pkg-config: --cflags --libs libsystemd-journal\n``` \n\n#### Documentation\n\nNew_journal() and New_journal_m() create a Journal struct. Journal.Emerg(), \nJournal.Alert(), Journal.Crit(), Journal.Err(), Journal.Warning(),\nJournal.Notice(), Journal.Info(), Journal.Debug() write to the systemd journal.\n\nEach method contains a format *f method; i.e. Infof, Errf.\n\nEach method also contains a *_a (array variation) method that allows sending your\nown fields as an array of SOMEFILE=value strings. An *_a_f variation supports\nfmt.Printf style arguments.\n\nEach method contains a *_m (map variation) method that allows sending your own\nfields. The map suppports string and []byte (binary).\n\nEach method also contains a *_m_f (map \u0026 format variation) method that supports\n[fmt.Printf](http://godoc.org/fmt#Printf) style arguments.\n\nEach of the methods will add journal fields GO_FILE, and GO_FUNC fields to the\njournal to indicate where the methods were called. The *_m_f methods can take\nnil map in order to only use the format functionality.\n\n#### Helpful Hints\n+ You may need to increase RateLimitInterval and/or RateLimitBurst settings in\njournald.conf when sending large amounts of data to the journal. Data will\nnot appear in the log when settings are too low. \n\n* journalctl will truncate output by default. journalctl uses `less` as it's\npager and sets it's own defaults via SYSTEMD_LESS. To restore the output, set\nthe SYSTEMD_LESS environment variable; i.e. `export SYSTEMD_LESS=FRXMK`. See\n`man journalctl`.\n\n#### Example\n\n```go\npackage main\nimport (\n\t\"io\"\n\t\"log\"\n\t\"sd\"\n)\n\nfunc main() {\n\n\tj := sd.New_journal()\n\tj.Alert(\"Alert example\")\n\n\t// COMMENT_2_BINARY = abcNULLabc\n\tm := map[string]interface{}{\"COMMENT_1\": \"This function ran successfully\",\n\t\t\"COMMENT_2_BINARY\": []byte{0x61, 0x62, 0x63, 0x00, 0x61, 0x62, 0x63},\n\t}\n\n\t// Use: \"journal -f --output verbose\" to see fields\n\tj.Alert_m(m, \"Alert_m exmaple\")\n\n\tj.Alert_m_f(m, \"Alert_m_f example: Salary: %v, Year: %v\", 0.00, 2014)\n\n\t// Use log package\n\t// Remove ANSI escape sequences\n\t// systemd will convert messages to binary with ANSI escapes sequences\n\tsd.Set_default_remove_ansi_escape(true)\n\tj := sd.New_journal()\n\t// systemd will output red text\n\tj.Set_writer_priority(sd.Log_err)\n\t// Hello World\n\t// Hello is green\n\t// World is yellow\n\ts := \"\\x1b[32mHello\\x1b[0m \\x1b[93mWorld\\x1b[0m\"\n\tlog.SetFlags(0)\n\t// Send to stderr and systemd-journald\n\tlog.SetOutput(io.MultiWriter(os.Stderr, j))\n\tlog.Println(s)\n}\n```\n##### Ouput\n```bash\n# tail the systemd journal \njournal -f --output verbose\n```\n\n#### License \n\nUse of this source code is governed by a BSD-2-Clause license that can be found\nin the LICENSE file.\n\n[![BSD-2-Clause License](img/osi_logo_100X133_90ppi_0.png)](https://opensource.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faletheia7%2Fsd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faletheia7%2Fsd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faletheia7%2Fsd/lists"}