{"id":28471798,"url":"https://github.com/peburrows/mongo_db_logger","last_synced_at":"2025-07-25T10:37:03.576Z","repository":{"id":676539,"uuid":"320146","full_name":"peburrows/mongo_db_logger","owner":"peburrows","description":"This project has moved!","archived":false,"fork":false,"pushed_at":"2011-03-16T06:56:41.000Z","size":310,"stargazers_count":94,"open_issues_count":0,"forks_count":53,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-01T22:36:02.877Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://github.com/customink/central_logger","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/peburrows.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-09-28T16:29:28.000Z","updated_at":"2022-12-06T20:18:49.000Z","dependencies_parsed_at":"2022-08-16T10:40:24.489Z","dependency_job_id":null,"html_url":"https://github.com/peburrows/mongo_db_logger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peburrows/mongo_db_logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peburrows%2Fmongo_db_logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peburrows%2Fmongo_db_logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peburrows%2Fmongo_db_logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peburrows%2Fmongo_db_logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peburrows","download_url":"https://codeload.github.com/peburrows/mongo_db_logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peburrows%2Fmongo_db_logger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266991173,"owners_count":24017739,"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-07-25T02:00:09.625Z","response_time":70,"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":[],"created_at":"2025-06-07T11:08:55.794Z","updated_at":"2025-07-25T10:37:03.542Z","avatar_url":"https://github.com/peburrows.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CentralLogger\n\nLog to a central MongoDB from Rails apps.\n\n## Usage\n\n1. If using Bundler, add the following to your Gemfile then refresh your dependencies by executing \"bundle install\":\n\n        gem \"central_logger\"\n\n1. If you're just using gem:\n\n        gem install central_logger\n\n1. Add the following line to your ApplicationController:\n\n        include CentralLogger::Filter\n\n1. If using Rails 3, SKIP this step.  Otherwise, add the following to config/environment.rb:\n\n       require 'central_logger'\n       CentralLogger::Initializer.initialize_deprecated_logger(config)\n\n1. Add mongo settings to database.yml for each environment in which you want to use the Central Logger. The central logger will also\n   look for a separate central_logger.yml or mongoid.yml (if you are using mongoid) before looking in database.yml.\n   In the central_logger.yml and mongoid.yml case, the settings should be defined without the 'mongo' subkey.\n\n   database.yml:\n\n        development:\n          adapter: mysql\n          database: my_app_development\n          user: root\n          mongo:\n            database: my_app               # required (the only required setting)\n            capsize: \u003c%= 10.megabytes %\u003e   # default: 250MB for production; 100MB otherwise\n            host: localhost                # default: localhost\n            port: 27017                    # default: 27017\n            replica_set: true              # default: false - Adds safe inserts and retries for ConnectionFailure during voting\n\n    central_logger.yml:\n\n        development:\n          database: my_app\n          capsize: \u003c%= 10.megabytes %\u003e\n          host: localhost\n          port: 27017\n          replica_set: true\n\n  With that in place, a new MongoDB document (record) will be created for each request and,\n  by default will record the following information: Runtime, IP Address, Request Time, Controller,\n  Action, Params, Application Name and All messages sent to the logger. The structure of the Mongo document looks like this:\n\n        {\n          'action'           : action_name,\n          'application_name' : application_name (rails root),\n          'controller'       : controller_name,\n          'ip'               : ip_address,\n          'messages'         : {\n                                 'info'  : [ ],\n                                 'debug' : [ ],\n                                 'error' : [ ],\n                                 'warn'  : [ ],\n                                 'fatal' : [ ]\n                               },\n          'params'           : { },\n          'path'             : path,\n          'request_time'     : date_of_request,\n          'runtime'          : elapsed_execution_time_in_milliseconds,\n          'url'              : full_url\n        }\n\n  Beyond that, if you want to add extra information to the base of the document\n  (let's say something like user_guid on every request that it's available),\n  you can just call the Rails.logger.add_metadata method on your logger like so\n  (for example from a before_filter):\n\n        # make sure we're using the CentralLogger in this environment\n        if Rails.logger.respond_to?(:add_metadata)\n          Rails.logger.add_metadata(:user_guid =\u003e @user_guid)\n        end\n\n## Examples\n\nAnd now, for a couple quick examples on getting ahold of this log data...\nFirst, here's how to get a handle on the MongoDB from within a Rails console:\n\n    \u003e\u003e db = Rails.logger.mongo_connection\n    =\u003e #\u0026lt;Mongo::DB:0x102f19ac0 @slave_ok=nil, @name=\"my_app\" ... \u0026gt;\n\n    \u003e\u003e collection = db[Rails.logger.mongo_collection_name]\n    =\u003e #\u0026lt;Mongo::Collection:0x1031b3ee8 @name=\"development_log\" ... \u0026gt;\n\nOnce you've got the collection, you can find all requests for a specific user (with guid):\n\n    \u003e\u003e cursor = collection.find(:user_guid =\u003e '12355')\n    =\u003e #\u0026lt;Mongo::Cursor:0x1031a3e30 ... \u0026gt;\n    \u003e\u003e cursor.count\n    =\u003e 5\n\nFind all requests that took more that one second to complete:\n\n    \u003e\u003e collection.find({:runtime =\u003e {'$gt' =\u003e 1000}}).count\n    =\u003e 3\n\nFind all order#show requests with a particular order id (id=order_id):\n\n    \u003e\u003e collection.find({\"controller\" =\u003e \"order\", \"action\"=\u003e \"show\", \"params.id\" =\u003e order_id})\n\nFind all requests with an exception that contains \"RoutingError\" in the message or stack trace:\n\n    \u003e\u003e collection.find({\"messages.error\" =\u003e /RoutingError/})\n\nFind all requests with a request_date greater than '11/18/2010 22:59:52 GMT'\n\n    \u003e\u003e collection.find({:request_time =\u003e {'$gt' =\u003e Time.utc(2010, 11, 18, 22, 59, 52)}})\n\nCopyright (c) 2009 Phil Burrows, released under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeburrows%2Fmongo_db_logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeburrows%2Fmongo_db_logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeburrows%2Fmongo_db_logger/lists"}