Skip to content

Instantly share code, notes, and snippets.

@visnup
Created February 8, 2011 00:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visnup/815607 to your computer and use it in GitHub Desktop.
Save visnup/815607 to your computer and use it in GitHub Desktop.
# trippy mongodb colorized logging by statement type
class Mongoid::Logger
def debug message
op =
case message
when /insert/ then "\e[0;32m(C)\e[0m"
when /find|cursor/ then "\e[0;34m(R)\e[0m"
when /update/ then "\e[0;33m(U)\e[0m"
when /remove/ then "\e[0;31m(D)\e[0m"
end
logger.debug("#{op} #{message}") if logger && logger.respond_to?(:debug)
end
end
@TomK32
Copy link

TomK32 commented Feb 8, 2011

This is great. But I'd love to see colours for any ObjectId in the output and also for the collection names :)

@visnup
Copy link
Author

visnup commented Feb 8, 2011

ooh good idea. I'm going to wait until the next mongo ruby driver is released for that though. they just updated it with easier to override instrumentation methods for those types of things.

@millisami
Copy link

@visnup I too liked the idea. Gonna watch it or have you already started?

@visnup
Copy link
Author

visnup commented Feb 11, 2011

ooh, mongo ruby driver 1.2.1 just got released. I'll see if I can update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment