Created
October 8, 2015 15:44
-
-
Save odigity/faba40e04d6210007cb7 to your computer and use it in GitHub Desktop.
Colorizing Sequel logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'colorize' | |
| class CLogger < Logger | |
| def info(message) | |
| color = case message | |
| when Regexp.union(%w[CREATE ALTER DROP]) | |
| :light_blue | |
| when Regexp.union(%w[INSERT UPDATE DELETE]) | |
| :light_yellow | |
| else | |
| :yellow | |
| end | |
| message = message.colorize(color) | |
| super(message) | |
| end | |
| end | |
| Sequel.mysql2(dbname, | |
| ...credentials... | |
| loggers: [CLogger.new($stdout)], | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment