{"id":18103131,"url":"https://github.com/theforeman/journald-logger","last_synced_at":"2025-04-13T19:01:30.231Z","repository":{"id":22553291,"uuid":"25894371","full_name":"theforeman/journald-logger","owner":"theforeman","description":"RubyGem: Logger for systemd-journal","archived":false,"fork":false,"pushed_at":"2022-03-30T06:42:23.000Z","size":49,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-09T23:43:18.317Z","etag":null,"topics":["hacktoberfest","logger","ruby","systemd-journal"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/theforeman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-28T23:09:40.000Z","updated_at":"2022-10-25T14:29:27.000Z","dependencies_parsed_at":"2022-08-21T07:30:57.438Z","dependency_job_id":null,"html_url":"https://github.com/theforeman/journald-logger","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theforeman%2Fjournald-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theforeman%2Fjournald-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theforeman%2Fjournald-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theforeman%2Fjournald-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theforeman","download_url":"https://codeload.github.com/theforeman/journald-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766726,"owners_count":21158301,"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":["hacktoberfest","logger","ruby","systemd-journal"],"created_at":"2024-10-31T22:10:25.238Z","updated_at":"2025-04-13T19:01:30.183Z","avatar_url":"https://github.com/theforeman.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# journald-logger\n\nA Logger drop-in replacement that logs directly to systemd-journal with some additional features\n\n## Usage\n\n```ruby\nrequire 'journald/logger'\n\nlogger = Journald::Logger.new('gandalf') # simple logger, sets SYSLOG_IDENTIFIER to 'gandalf'\nlogger = Journald::TraceLogger.new('gandalf') # tracing logger, logs caller's file, line number and function name\n```\n\n## Logger replacement\n\nThis gem is designed to be accurate drop-in Logger replacement\n\n```ruby\nlogger.warn \"you shall not pass!\"           # works\nlogger.info(\"gollum\") { \"my preciousss\" }   # also works!\nlogger.progname = \"saruman\"                 # sets value for SYSLOG_IDENTIFIER to 'saruman'\nlogger.formatter = SomeFormatter.new        # does nothing, journald-logger does not require a formatter\nlogger.close                                # does nothing, nothing to close\n```\n\nWe map Ruby severity to Syslog priority by this map\n\n```ruby\nLEVEL_MAP = {\n  ::Logger::UNKNOWN =\u003e LOG_ALERT,\n  ::Logger::FATAL   =\u003e LOG_CRIT,\n  ::Logger::ERROR   =\u003e LOG_ERR,\n  ::Logger::WARN    =\u003e LOG_WARNING,\n  ::Logger::INFO    =\u003e LOG_INFO,\n  ::Logger::DEBUG   =\u003e LOG_DEBUG,\n}\n```\n\nYou may notice it's somewhat different from the one from Syslog::Logger\n\n## Setting report level\n\n```ruby\nlogger = Journald::Logger.new('gandalf', Journald::LOG_NOTICE) # set minimal reporting level to notice\nlogger.min_priority   = Journald::LOG_NOTICE # runtime change of minimal priority\nlogger.level          = Logger::WARN # use Logger severity\nlogger.sev_threshold  = Logger::INFO # please pay attention that Logger severity lacks several levels e.g. 'notice'\n```\n\n## Tags\n\nTags are used to add systemd-journal fields to all subsequent log calls until removed\n\n```ruby\nlogger = Journald::Logger.new('gandalf', world: 'arda') # set world tag in costructor\nlogger.tag location: 'shire', weapon: 'staff' # add/replace location and weapon\nlogger.tag(location: 'moria', object: 'balrog') do # change location and use object in the block\n  # log as 'MESSAGE=you shall not pass!', 'PRIORITY=4', 'LOCATION=moria', 'OBJECT=balrog', 'WORLD=arda', 'WEAPON=staff'\n  logger.warn 'you shall not pass!'\nend # return location \u0026 object to the previous state\n# log as 'MESSAGE=That was not in canon!', 'PRIORITY=6', 'LOCATION=shire', 'WORLD=arda', 'WEAPON=staff'\nlogger.info 'That was not in canon!'\nlogger.untag :location, :weapon # remove location and weapon\n```\n\nTag names must follow systemd-journal fields naming convention:\nletters, numbers, underscores, cannot begin with underscore. Library upcases all letters automatically\n\n## systemd-journal style\n\nTwo methods which look similarly to native systemd-journal api\n\n```ruby\nlogger.send_message(\n  message: 'hi!',\n  priority: Journald::LOG_NOTICE,\n  any_field: 'any_value',\n) # tags will be added here\nlogger.print Journald::LOG_NOTICE, 'hi!' # and here\n```\n\n## Syslog style\n\nJust to add some more confusion you may use methods with syslog severity names prefixed with ```log_```\n\n```ruby\nlogger.log_err 'Error'\nlogger.log_debug 'Debug'\n```\n\n## Exception logging\n\n```ruby\nbegin\n  raise \"Aw, snap!\"\nrescue =\u003e e\n  logger.exception e # log exception with LOG_ERR level by default\n  logger.exception e, severity: Logger::WARN        # use Logger severity\n  logger.exception e, priority: Journald::LOG_ALERT # use Syslog priority \nend\n```\n\nException logger automatically fills the following fields:\n\n```\nEXCEPTION_CLASS=ExceptionRealClassName\nEXCEPTION_MESSAGE=Original exception message\nBACKTRACE=full backtrace\nCAUSE=exception cause (Ruby \u003e= 2.1)\nGEM_LOGGER_MESSAGE_TYPE=Exception\n```\n\nIn Ruby 2.1+ it also tries to log ```CODE_LINE```, ```CODE_FILE``` and ```CODE_FUNC``` and to recurse into Cause and log it into a separate message with ```GEM_LOGGER_MESSAGE_TYPE=ExceptionCause```\n\n## Authors\n\nThis library was written by Anton Smirnov and currently maintained by https://www.theforeman.org developers.\n\n## License\n\nMIT, see LICENSE.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheforeman%2Fjournald-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheforeman%2Fjournald-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheforeman%2Fjournald-logger/lists"}