Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Bunyan is a thin ruby wrapper around a MongoDB capped collection, created with high-performance, flexible logging in mind.
Bunyan is not intended to be used as a drop-in replacement for the default rails logger. If you need to do this, please see peburrows' mongo_db_logger.
However, there is planned support for a flexible middleware component to drop in to your rails app.
gem install bunyan
The only configuration options required are the database and collection name.
For rails apps, put the following config block in an initializer.
# config/initializers/bunyan.rb
Bunyan::Logger.configure do
# required options
database 'bunyan_logger'
collection 'development_log'
# optional
host 'some.remote.host' # defaults to localhost
port '12345' # defaults to 27017
disabled true
# other connection option
# Specify a valid ruby driver connection object (single / pair)
# if you do so, host / port are ignored
connection = $connection
end
# Gemfile
gem 'bson_ext', '1.1' # set the version to whatever the current version of bson the mongo gem is using
You can access the bunyan logger anywhere is your app via Bunyan::Logger. The Logger class is implemented as a singleton, and you can call any instance method on the Logger class. This is implemented with some method_missing magic, which is explained in a bit more detail below.
To make use of Bunyan in your web apps, you need some way to capture request data.
I have added an example middleware (which is extremely, extremely ugly) which you
can find at examples/middleware.rb
.
There are plans for a standard middleware API, but it has not yet been implemented. If you have interest in helping/collaborating on this feature, please get in touch with me.
Until the middleware API is complete, please use this example middleware at your own risk!
Bunyan makes heavy usage of method_missing both at the class and instance level. At the class level, this is purely for convenience to pass missing class methods to the singleton instance, which precludes us from needing to use Logger.instance directly. At the instance level, method_missing is used to provide a very thin layer around MongoDB, via the Mongo driver.
The net effect of this is that there is no reason to muck around with calling methods directly on Bunyan::Logger.instance, because all methods that don't already exist at the class level will be sent to Bunyan::Logger.instance.
Bunyan::Logger.count == Bunyan::Logger.instance.count # => true
Also, you can call any instance methods Bunyan::Logger that you would otherwise call on a Mongo collection object.
FAQs
Unknown package
We found that bunyan demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.