cr-color-logging
Version, currently master branch1 version
- master branchlatestJun 14, 2022
github.com/crystal-community/cr-color-logging
No description declared in shard.yml.
Installation
# Add this to your shard.yml
dependencies:
cr-color-logging:
github: crystal-community/cr-color-logging
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
1.4.0- License
- MIT
- Author
- Troy Sornson
Dependencies
Development Dependencies
README
Color Logging Formatter
This shard adds a new module ColorLogging as well as a new short formatter ShortColorFormat to help add a bit of color to your otherwise excellent log lines.
Installation
-
Add the dependency to your
shard.yml:dependencies: cr-color-logging: github: vici37/cr-color-logging -
Run
shards install
Usage
require "cr-color-logging"
# This will output all debug and above severity log lines to STDOUT, colored via the ShortColorFormat formatter.
# By default, no colors are set and must be defined.
Log.setup(:debug, Log::IOBackend.new(formatter: Log::ShortColorFormat))
# Define the color you want for which part of the log message. Colors
# are the same as the ones defined in the `colorize` module.
Log::ShortColorFormat.with_color("severity", :red)
Log::ShortColorFormat.with_color("timestamp", :blue)
# Outputting a log now is as simple as:
Log.for(MyClass).info { "my information message" }
The full list of parts that the ShortColorFormat supports are:
timestamp
message
severity
source
after_source
before_data
data
before_context
context
exception
progname
pid
string
The ShortColorFormat was defined using the same string as the standard ShortFormat here. A similar macro is also defined for the ColorLogging module to define custom formats as well:
ColorFormat.define_formatter MyFormat "#{timestamp(after: ":")} #{severity(before: "[", after: "]")} #{message}"
# All parts, with exception to `string`, support a before_ and after_ prefixed part to color those
# specific pieces. If omitted, they inherit from the base part.
MyFormat.with_color("before_severity", :yellow)
MyFormat.with_color("after_severity", :yellow)
MyFormat.with_color("severity", :red)
# It might also be good to skip specific part coloring if a log line is of a sufficient severity.
# This will color the entire line this color if the severity matches.
MyFormat.with_colored_sevirity(Log::Severity::Error, :red)
Contributing
- Fork it (https://github.com/your-github-user/color-logging/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Troy Sornson - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Jun 14, 2022
- Crystal
1.4.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/crystal-community/cr-color-logging
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 14, 2026
- Synced
- Aug 14, 2026
- Versions
- 1