{"id":18697667,"url":"https://github.com/federicoceratto/nim-morelogging","last_synced_at":"2025-04-12T07:32:17.393Z","repository":{"id":17960943,"uuid":"83087492","full_name":"FedericoCeratto/nim-morelogging","owner":"FedericoCeratto","description":"Logging library for Nim","archived":false,"fork":false,"pushed_at":"2023-05-07T11:15:30.000Z","size":38,"stargazers_count":51,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-04T03:08:28.016Z","etag":null,"topics":["journald","log","logging","nim","nim-lang","syslog"],"latest_commit_sha":null,"homepage":null,"language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FedericoCeratto.png","metadata":{"files":{"readme":"README.adoc","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}},"created_at":"2017-02-24T22:17:02.000Z","updated_at":"2024-06-24T21:28:56.000Z","dependencies_parsed_at":"2024-01-06T12:07:54.141Z","dependency_job_id":"e7d7c570-a77c-4130-904d-f9aeba6e838a","html_url":"https://github.com/FedericoCeratto/nim-morelogging","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoCeratto%2Fnim-morelogging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoCeratto%2Fnim-morelogging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoCeratto%2Fnim-morelogging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FedericoCeratto%2Fnim-morelogging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FedericoCeratto","download_url":"https://codeload.github.com/FedericoCeratto/nim-morelogging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223504276,"owners_count":17156286,"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":["journald","log","logging","nim","nim-lang","syslog"],"created_at":"2024-11-07T11:25:14.851Z","updated_at":"2024-11-07T11:25:15.783Z","avatar_url":"https://github.com/FedericoCeratto.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"== Morelogging\n\nA set of logging utilities for Nim.\n\nimage:https://img.shields.io/badge/status-beta-orange.svg[badge]\nimage:https://img.shields.io/github/tag/FedericoCeratto/nim-morelogging.svg[tags]\nimage:https://img.shields.io/badge/License-LGPL%20v3-blue.svg[License]\n\n.Features:\n[none]\n- [x] File rotation\n- [x] Compression\n- [x] Templated log file name\n- [x] Templated log messages\n- [x] Threaded log buffering\n- [x] Async log buffering\n- [x] Logging, file rotation and compression do not block the caller\n- [x] Sensible defaults: log to \"\u003cappname\u003e.\u003cdate\u003e.log\", daily log rotation\n- [x] Log to systemd Journald. Support structured entries.\n- [x] Support Linux, OSX, Windows\n- [x] Functional-tested\n\n.Roadmap:\n- [ ] Logging hierarchy\n- [ ] Do not crash the application on write failure (e.g. broken or full disk, permission errors) - switch to logging to stderr\n- [ ] Rotate logfile on SIGHUP signal\n- [ ] Structured logging and optional fields\n\n.Installation\n[source,bash]\n----\n$ # install Nim using APT or from the upstream website\n$ sudo apt-get install nim\n$ # install nimble and then:\n$ nimble install morelogging\n----\n\n.Usage\n[source,nim]\n----\nimport morelogging\n\nlet log = newAsyncFileLogger()\nlog.debug(\"debug\")\nlog.info(\"info\")\nlog.warn(\"warn\")\nlog.error(\"error\")\nlog.fatal(\"fatal\")\n----\n\n\n=== Log message formatting\n\nThe following formatters are supported:\n\n  $date\n  $time\n  $datetime\n  $app\n  $appdir\n  $appname\n  $levelid\n  $levelname\n\nMessages with level below level_threshold are ignored.\n\n=== Async and threaded loggers\n\nIf buffer_size is positive, messages are buffered internally up to writeout_interval_ms\n\nMessages with level \u003e= flush_threshold are flushed out immediately.\n\n[source,nim]\n----\nproc newAsyncFileLogger*(\n    filename_tpl = \"$app.$y$MM$dd.log\",\n    flush_threshold = lvlError,\n    fmtStr = \"$datetime $levelname \",\n    level_threshold = lvlAll,\n    mode: FileMode = fmAppend,\n    writeout_interval_ms = 100,\n    buffer_size = 1_048_576\n  ): AsyncFileLogger =\n\nproc newThreadFileLogger*(\n    filename_tpl = \"$app.$y$MM$dd.log\",\n    fmtStr = \"$datetime $levelname \",\n    level_threshold = lvlAll,\n    mode: FileMode = fmAppend,\n    writeout_interval_ms = 100,\n  ): ThreadFileLogger =\n\nproc newThreadRotatingFileLogger*(\n    compress = false,\n    filename_tpl = \"$app.$y$MM$dd.log\",\n    fmtStr = \"$datetime $levelname \",\n    level_threshold = lvlAll,\n    mode: FileMode = fmAppend,\n    rotate_interval = \"1d\",\n    writeout_interval_ms = 100,\n  ): ThreadRotatingFileLogger\n----\n\n==== Generating log file names dynamically\n\nFilenames are generated from filename_tpl\nDefault value: \"$app.$y$MM$dd.log\"\nThe following formatters are supported:\n\n  $y         year\n  $MM        month\n  $dd        day\n  $hh        hour\n  $mm        minute\n  $ss        second\n  $hostname  hostname\n  $appname   application name\n\n=== Systemd's Journald logger (recommended)\n\nJournald supports logging user-defined key-value pairs and provides fast indexing.\n\nEnable with -d:systemd\n\n.Usage:\n[source,nim]\n----\nlet log = newJournaldLogger()\nlog.info(\"hello world\", {\"key_1\": \"value_1\"})\n----\n\nKeys are converted to uppercase. They can contain underscores but not as the first character.\n\nJournaldLogger will automatically add CODE_FILE, CODE_FUNC, CODE_LINE keys to show the filename, function and line number that generated the log message.\n\nNote: '--stackTrace:on' and '--lineTrace:on' are required when building in release mode to enable this feature.\n\n\nYou can override them by passing the keys in uppercase with your own values.\n\n\n.Output example:\n[source,bash]\n----\nsudo journalctl -e -o json-pretty KEY_1=value_1 -n1 --no-pager\n{\n  \"PRIORITY\" : \"5\",\n  \"_TRANSPORT\" : \"journal\",\n  \"_UID\" : \"1000\",\n  \"_GID\" : \"1000\",\n  \"MESSAGE\" : \"hello world\",\n  \"KEY_1\" : \"value_1\",\n  \"CODE_FUNC\" : \"myfunction\",\n  \"CODE_FILE\" : \"mytest.nim\",\n  \"CODE_LINE\" : \"24\",\n  \u003c other lines redacted \u003e\n  \u003c ... \u003e\n}\n----\n\n=== Stdout logger\n\nUseful mostly for debugging.\n\n.Usage:\n[source,nim]\n----\nimport morelogging\nlet log = newStdoutLogger(fmtStr=\"$time \")\nlog.info(\"hello world\")\n----\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedericoceratto%2Fnim-morelogging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffedericoceratto%2Fnim-morelogging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedericoceratto%2Fnim-morelogging/lists"}