
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Control logging at runtime with an environment variable
Usage:
LOGLEVEL=WARN rails server
Loglevel will direct your logging to STDOUT
(as suggested in
the 12-factor app). See the Log Device section
below for how to control where your logging goes.
Control which components create visible log entries by simply setting an environment variable. For instance:
LOGLEVEL=DEBUG,NOAR,NOHTTP rails server
would set the Rails logger level to DEBUG
but would suppress messages from
the ActiveRecord logger and the HttpLogger gem.
Here are the available settings:
Option | Description |
---|---|
FATAL | Equivalent to config.log_level = :fatal |
ERROR | Equivalent to config.log_level = :error |
WARN | Equivalent to config.log_level = :warn |
INFO | Equivalent to config.log_level = :info |
DEBUG | Equivalent to config.log_level = :debug |
NOAR | Do not show ActiveRecord messages |
HTTP | Show HTTP messages |
NOHTTP | Do not show HTTP messages |
NOHEADERS | Do not include response headers in HTTP log |
NOBODY | Do not include response body in HTTP log |
The examples in this document assume Loglevel is being used in a Rails environment but it doesn't depend on Rails and can be used in other contexts.
There are specific options to handle Railsy logging scenarios: things like controlling ActiveRecord logging.
The HttpLogger gem works in a slightly different way. When we set the level for HttpLogger we are setting the level at which the HTTP messages are logged.
In the Loglevel environment this will be :debug
, so you will only see HTTP messages if LOGLEVEL=DEBUG
. If you want to see HTTP messages at a less verbose level then use the HTTP
parameter when setting LOGLEVEL
, like this:
LOGLEVEL=INFO,HTTP rails server
This will show all messages at INFO
and above and will also show HTTP messages.
If you want to see DEBUG
messages but not HTTP messages then use the NOHTTP
parameter:
LOGLEVEL=DEBUG,NOHTTP rails server
In a Rails context, we want Loglevel to be configured after Rails's own logger has been initialized but before any other app initialization has taken place. This allows us to control the logging of other components' initialization.
The best way I have found of doing this is to create a script in the
config/initializers
directory. These initializers are executed in alphabetical
order so you can control when Loglevel is initialized by carefully naming your
script.
To initialize Loglevel first, create a script called 01_loglevel.rb
with the
single line
Loglevel.setup
To understand which other points in the Rails initialization process you can choose, see The Rails Initialization Process.
By default Loglevel will instantiate Ruby's default Logger class (in a Rails context this will be something like ActiveSupport::TaggedLogging). If you want to use a different logger then you can use an environment variable to tell Loglevel which logger you use:
LOGLEVEL_LOGGER=Log4r LOGLEVEL=DEBUG rails server
By default Loglevel will setup logging to the STDOUT
device. If you want to
use a different device there's an environment variable for that:
LOGLEVEL_DEVICE=tmp/test.log LOGLEVEL=DEBUG rails server
By default, Loglevel will setup the logger for Rails, ActiveRecord::Base and HttpLogger if they are present.
It will also setup logging for any other classes that you include in an environment variable:
LOGLEVEL_CLASSES=MyClass LOGLEVEL=DEBUG rails server
The only methods the class must support are logger
and logger=
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that loglevel 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
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.