{"id":29272093,"url":"https://github.com/acook/logsaber","last_synced_at":"2025-07-05T00:10:32.271Z","repository":{"id":7223385,"uuid":"8530939","full_name":"acook/logsaber","owner":"acook","description":"A logger for a more civilized age.","archived":false,"fork":false,"pushed_at":"2024-01-03T07:14:37.000Z","size":71,"stargazers_count":4,"open_issues_count":9,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-21T09:59:29.520Z","etag":null,"topics":["formatting","logging","ruby"],"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/acook.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2013-03-03T03:02:04.000Z","updated_at":"2023-02-20T14:41:55.000Z","dependencies_parsed_at":"2024-01-03T08:26:41.637Z","dependency_job_id":"1ae91ca7-15f3-4097-aa97-65bf2ae5a4b2","html_url":"https://github.com/acook/logsaber","commit_stats":{"total_commits":75,"total_committers":2,"mean_commits":37.5,"dds":"0.22666666666666668","last_synced_commit":"c98ed65a4b2e8661176b29ccb19739b44d14d572"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/acook/logsaber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acook%2Flogsaber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acook%2Flogsaber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acook%2Flogsaber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acook%2Flogsaber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acook","download_url":"https://codeload.github.com/acook/logsaber/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acook%2Flogsaber/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262058227,"owners_count":23252031,"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":["formatting","logging","ruby"],"created_at":"2025-07-05T00:10:31.536Z","updated_at":"2025-07-05T00:10:32.262Z","avatar_url":"https://github.com/acook.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Logsaber\n=========\n\nA logger for a more civilized age.\n\nReference documentation for the [Latest Released](http://rubydoc.info/gems/logsaber/file/README.markdown) and [Edge Version](https://github.com/acook/logsaber#readme) is available.\n\n[![Gem Version](https://img.shields.io/gem/v/logsaber.svg?style=for-the-badge)](https://rubygems.org/gems/logsaber/)\n[![CircleCI](https://img.shields.io/circleci/build/github/acook/logsaber?style=for-the-badge\u0026token=a4744dd3060c86c5eec00908ddbc43da0b972847)](https://app.circleci.com/pipelines/github/acook/logsaber)\n[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/acook/logsaber?style=for-the-badge)](https://codeclimate.com/github/acook/logsaber)\n\nPhilosophy / Why Logsaber?\n--------------------------\n\nLogsaber is a lot like Ruby's built in [Logger](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html) class,\nbut it is based on the real world experience of how I actually use loggers.\n\nThe biggest difference is Logsaber's intelligent output.\n\n### Intelligent Logging\n\nIf you pass a single string argument to an event method Logsaber will just log that string without any frills.\n\nBut if you pass it an object like an Array:\n\n```ruby\narray = [1,2,3]\n$log.info array\n```\n\n...it will inspect the array and the output will reflect the intent:\n\n```\n2013-03-02 21:08:30.797 [ INFO] 32981 | OBJ : [1, 2, 3]\n```\n\nEven better, if you pass in two arguments, like this:\n\n```ruby\n$log.info 'using environment', ENV['MYAPP_ENV']\n```\n\n...the first will be treated as a label, and the second as an object to be inspected:\n\n```\n2013-03-02 20:11:22.630 [ INFO] 31395 | using environment : development\n```\n\nIf you pass in a block:\n\n```ruby\n@log.info :heavy, 'this could be resource intensive' do\n  10000.times.to_a.last\nend\n```\n\n...Logsaber will intelligently evaluate it and format your output sanely:\n\n```\n2013-03-02 21:20:04.715 [ INFO] 32981 | heavy : \"this could be resource intensive\" | 9999\n```\n\nAlso, since blocks are lazy loaded, they won't be evaluated at all if the severity is below the log level threshold,\nthis is really important if your debug output is resource intensive.\n\n### Ruby Logger Limitations Surpassed\n\nThere's also some complaints about the native Logger than I address:\n\n1. You can't specify the log level on instantiation.\n\n  Logsaber lets you set the log level when you create it:\n\n  ```ruby\n  $log = Logsaber.create level: :warn\n  ```\n\n  But you can still change the default later:\n\n  ```ruby\n  $log.level = :info\n  ```\n\n2. You must specify the \"progname\" for every event.\n\n  Logsaber lets you set your app's name when you create it:\n\n  ```ruby\n  $log = Logsaber.create appname: 'MyApp'\n  ```\n\n  Or change it to something else at any time:\n\n  ```ruby\n  $log.appname = 'SomethingElse'\n  ```\n\n  ...and the output will look like this:\n\n  ```\n  2013-03-03 16:50:43.595 [ INFO] SomethingElse:8881 | MSG : ohai\n  ```\n\nInstallation\n------------\n\nUse [Bundler](http://gembundler.com):\n\n```ruby\n# in your Gemfile\ngem 'logsaber'\n```\n\nSetup\n-----\n\nGive it a filename and it will log to a file:\n\n```ruby\n$log = Logsaber.create './log/my_app.log'\n```\n\nOr you log to an IO (`$stdout` is the default, good for debugging):\n\n```ruby\n$log = Logsaber.create $stdout\n```\n\nIt can even log to a StringIO (good for test environments):\n\n```ruby\nrequire 'stringio'\nstringio = StringIO.create\n\n$log = Logsaber.create stringio\n```\n\nYou can also set the log level on initialization (it's `:info` by default):\n\n```ruby\n$log = Logsaber.create level: :debug\n```\n\nAnd you can optionally specify the name of your app (which is `nil` by default, it's displayed next to the pid in the output):\n\n```ruby\n$log = Logsaber.create appname: 'MyApp'\n```\n\nExample with all options:\n\n```ruby\nLogsaber.create 'my_app.log', level: :debug, appname: 'MyApp'\n```\n\nUsage\n-----\n\nThen you can use any of the logging commands:\n\n`debug`, `info`, `warn`, `error`, or `fatal`\n\nlike this:\n\n```ruby\n$log.warn 'Something might be amiss here'\n```\n\nor like this:\n\n```ruby\n$log.error 'PEBKAC', @user\n```\n\nor maybe:\n\n```ruby\n@log.debug \"What is this I don't even.\" do\n  big_data.inspect\nend\n```\n\nContributing\n------------\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\nAuthor\n======\n\n    Anthony M. Cook 2013-2021\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facook%2Flogsaber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facook%2Flogsaber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facook%2Flogsaber/lists"}