aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/log_subscriber.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #20921 from pboling/fix-sql-colors-in-log-subscriberRafael Mendonça França2015-09-091-7/+27
|\ | | | | | | Fix and Improve sql logging coloration in `ActiveRecord::LogSubscriber`.
| * Remove extraneous `then` from case statementPeter Boling2015-07-171-12/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - CR feedback from @egilburg Additionally - Move logic for colorizing the payload name into a separate method - Make some `ActiveRecord::LogSubscriber` instance methods private for clarity: - `colorize_payload_name` - `sql_color` - `logger` - Improve Changelog Documentation GH #20885
| * Improve sql logging coloration in `ActiveRecord::LogSubscriber`.Peter Boling2015-07-171-7/+21
|/ | | | | | | | | | | | | | | | | | | | | | | - Improves coloring for statements like: # Become WHITE SELECT * FROM ( SELECT * FROM mytable FOR UPDATE ) ss WHERE col1 = 5; LOCK TABLE table_name IN ACCESS EXCLUSIVE MODE; # Becomes RED ROLLBACK - Reinstates the coloration of the `payload[:name]`. Instead of simple alternating colors, adds meaning: - `MAGENTA` for `"SQL"` or `blank?` payload names - `CYAN` for Model Load/Exists - Introduces specs for sql coloration. - Introduces specs for payload name coloration. GH#20885
* More granular console SQL colorationChris Tonkinson2015-06-231-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new coloration approach makes it easier to scan the rails console for specific types of activity with more fine-grained visual cues. Virtual terminal ANSI color escape codes are used when displaying SQL statements in the rails console. The former implementation alternates line prefix information (including the statement name and execution latency) between CYAN and MAGENTA. This visually differentiates any SQL statements in the log and is useful for quickly scanning for database activity. While a great idea and a solid foundation, alternating between just two colors on an even/odd basis (much like striping an HTML table) can be improved upon. This patch replaces the even/odd striping with a more comprehensive scheme that applies coloration based on the type of statement being run. Every statement logged has its prefix (name and latency) colored white (as the statement body was previously). The statement body is now colored according to the nature of the statement: - INSERT statements are GREEN (symbolic of creation or genesis) - SELECT statements are BLUE (typically used for informational displays, as SELECT statements do not normally have side-effects) - DELETE statements are RED (commonly used to indicate the danger of a destructive action) - UPDATE statements are YELLOW (it's like a less extreme RED :P) - TRANSACTION statements are CYAN (arbitrary) - and any other statements are MAGENTA (again, arbitrary)
* Don't invoke sql_runtime if logger is not set to infoeileencodes2015-04-041-1/+2
| | | | | | | | | `sql_runtime` was getting invoked even when the logger was set to fatal. This ensures that does not happen by checking that the logger is set to info level before logging the view runtime. This reduces the number of times `sql_runtime` is called for integration tests with a fatal logger from 6 to 2.
* Remove Relation#bind_paramsSean Griffin2015-01-271-13/+7
| | | | | | | | `bound_attributes` is now used universally across the board, removing the need for the conversion layer. These changes are mostly mechanical, with the exception of the log subscriber. Additional, we had to implement `hash` on the attribute objects, so they could be used as a key for query caching.
* Stop special casing null binary data in loggingSean Griffin2015-01-101-2/+2
| | | | | | There's very little value in logging "<NULL binary data>" instead of just "nil". I'd like to remove the column from the equation entirely, and this case is preventing us from doing so.
* Invert the if/else clauseRafael Mendonça França2014-05-041-1/+1
| | | | The case where the value is present is more common
* Fix exception when logging SQL w/ nil binary value.James Coleman2014-05-021-1/+1
|
* type casted PG bytea values are represented as a Hash.Yves Senn2013-11-091-0/+2
| | | | | This is a follow up to: 97f0d9a0dd12e7ad634815eecfeff866f64aad92 This change is also related to: df0edafac9eb47cd971970a9e7b13a3eaddf214e
* Cleanup identitymap logger from LogSubscriberArthur Neves2013-09-281-11/+2
| | | | Also renaming ivar @odd_or_even to @odd
* log the sql that is actually sent to the databaseNeeraj Singh2013-06-191-1/+1
| | | | | | | | | | | | If I have a query that produces sql `WHERE "users"."name" = 'a b'` then in the log all the whitespace is being squeezed. So the sql that is printed in the log is `WHERE "users"."name" = 'a b'`. This can be confusing. This commit fixes it by ensuring that whitespace is not squeezed. fixes #10982
* removes calls to AR::Runtime.instanceXavier Noria2013-04-131-2/+2
| | | | | | | | | | Registries have class-level accessors to write clean code, let's use them. This makes style uniform also with existing usage in ScopeRegistry and InstrumentationRegistry. If performance of the method_missing callback was ever considered to be a concern, then we should stop using it altogether and probably remove the callback. But while we have the feature we should use it.
* Created a runtime registry for thread local variables in active record.wangjohn2013-04-091-2/+2
|
* Ignore binds payload with nil column in AR log subscriberCarlos Antonio da Silva2013-01-081-5/+7
| | | | | | | | | | | | | Some tests were raising the following error: Could not log "sql.active_record" event. NoMethodError: undefined method `type' for nil:NilClass` Due to the way binds were being logged, the column info was considered always present, but that is not true for some of the tests listed in the issue. Closes #8806.
* Skip binary data with binds test for mysql2, fix buildCarlos Antonio da Silva2012-12-141-1/+1
| | | | | | | Mysql2 doesn't support binds, which means no binds payload is set when logging, so the logic to render binary data differently here doesn't work. Introduced in 99d142a9375f9ba1960863b3cc745265aa9a14df.
* Do not log the binding values for binary columns.Matthew M. Boedicker2012-12-141-1/+11
| | | | They tend to be large and not very useful in the log.
* Optimize log subscribers to check if the log level is sufficient before ↵Brian Durand2012-09-301-4/+6
| | | | performing an operations.
* implements a much faster auto EXPLAIN, closes #3843 [José Valim & Xavier Noria]Xavier Noria2011-12-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | This commit vastly reduces the impact of auto explain logging when enabled, while keeping a negligible cost when disabled. The first implementation was based on the idea of subscribing to "sql.active_record" when needed, and unsubscribing once done. This is the idea behind AR::Relation#explain. Subscribe, collect, unsubscribe. But with the current implementation of notifications unsubscribing is costly, because it wipes an internal cache and that puts a penalty on the next event. So we are switching to an approach where a long-running subscriber is listening. Instead of collecting the queries with a closure in a dedicated subscriber, now we setup a thread local. If the feature is disabled by setting the threshold to nil, the subscriber will call a method that does nothing. That's totally cheap.
* Make the identity map use the instrumentation infrastructure so we can style ↵David Heinemeier Hansson2011-05-011-0/+9
| | | | the messages nicely with colors (FIXME: Can someone look into why the test is not working?)
* sql logger ignores schema statementsAaron Patterson2011-03-281-0/+3
|
* fixing tests on 1.8, using a list of lists because order is importantAaron Patterson2011-02-101-1/+3
|
* simplify bind parameter loggingAaron Patterson2011-02-101-3/+1
|
* bind parameters are logged to debug logAaron Patterson2011-02-101-4/+12
|
* Move runtime back to the Thread.currentJosé Valim2010-07-261-3/+15
|
* Cache connection access.José Valim2010-07-251-4/+1
|
* Move runtime back to connection.José Valim2010-07-251-15/+6
|
* Revert the previous three commits.José Valim2010-07-251-1/+15
| | | | | | * AS::Notifications#instrument should not measure anything, it is not its responsibility; * Adding another argument to AS::Notifications#instrument API needs to be properly discussed;
* use a hash to collect optional statistics about the instrumentationAaron Patterson2010-07-251-15/+1
|
* runtime should be properly initialized.José Valim2010-07-251-2/+1
|
* Move runtime to log subscriber.José Valim2010-07-251-6/+16
|
* Get rid of instrumenter.elapsed.José Valim2010-07-241-0/+5
|
* Minor performance improvment in notifications/fanout and ↵Daniel Guettler2010-07-191-0/+2
| | | | active_record/log_subscriber [#5098 state:open]
* avoid const lookup. we know what these constants are in advanceAaron Patterson2010-07-191-3/+3
|
* Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing ↵José Valim2010-06-241-0/+32
frameworks like ActiveRecord and ActiveResource to log outsude Rails::Application [#4816 state:resolved]