turn off SQL logging while keeping settings.DEBUG?
When settings.DEBUG is True, Django uses CursorDebugWrapper instead of CursorWrapper. This is what appends the queries to connection.queries and consumes memory. I would monkey-patch the connection wrapper to always use CursorWrapper:
from django.conf import settings
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.utils import CursorWrapper
if settings.DEBUG:
BaseDatabaseWrapper.make_debug_cursor = lambda self, cursor: CursorWrapper(cursor, self)
Place this in some file that gets imported early in your application.
Disabling logging like others suggest won't fix the problem, because CursorDebugWrapper still stores the queries in connection.queries even if logging is off.
Disable Rails SQL logging in console
To turn it off:
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
To turn it back on:
ActiveRecord::Base.logger = old_logger
How to stop sql logging in debug mode?
In Django 1.3 this can be done rather simply with the inclusion of logging. In summary the way I do it is very similar to the docs and keep the focus of logging on my application. My settings.py file currently looks like this.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': "[%(asctime)s] %(levelname)s [%(name)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'django.utils.log.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'standard'
},
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
'level': 'INFO',
},
'django.db.backends': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
'apps': {
'handlers': ['console'],
'level': 'DEBUG',
},
}
}
If you are using an older version of Django you can setup logging by using filters (Yes you can do this in 1.3 too.) This SO post should provide you with what you need to get going.
Edit Update
Again following the documentation which gives an example combined with this post should get you where you need to go.
- Add in a
django
handler and propagate it down the chain.. - Add in a
django.db.backends
which doesn't propagate but raise the noise floor to ERROR
I don't think there is anything else?
HTH
How do I turn off Rails SQL logging in test?
Ok I found it. This worked:
config.after_initialize do
ActiveRecord::Base.logger = nil
end
Can't avoid hibernate logging SQL to console with Spring Boot and Logback
If you set the hibernate.show_sql
to true
, Hibernate will simply print the SQL statement to the console (not to be confused with logging under org.hibernate.SQL
). SqlStatementLogger
is responsible for logging the SQL statements and its logStatement
looks like:
public void logStatement(String statement, Formatter formatter) {
if ( format ) {
if ( logToStdout || LOG.isDebugEnabled() ) {
statement = formatter.format( statement );
}
}
LOG.debug( statement );
if ( logToStdout ) {
System.out.println( "Hibernate: " + statement );
}
}
So, if you do not want to see the queries on the console, just disable the hibernate.show_sql
by setting it to false
or just removing it altogether. In Spring Boot, just add this to your application.properties
:
spring.jpa.show-sql=false
Disable query logging in Rails 3.0.x, but allowing debug information
unfortunately the debugging options in rails are really bad. there is no namespacing of log-messages (by class ie like you would in java) and most of the log-levels are chosen in a fashion that i tend to shake my head about it (why is rendering partials logged on info-level?).
rails would greatly benefit from using a decent logging-library like log4r and using features like namespacing.
(end of rant)
Turning off hibernate logging console output
Try to set more reasonable logging level. Setting logging level to info
means that only log event at info
or higher level (warn
, error
and fatal
) are logged, that is debug
logging events are ignored.
log4j.logger.org.hibernate=info
or in XML version of log4j config file:
<logger name="org.hibernate">
<level value="info"/>
</logger>
See also log4j manual.
Related Topics
How to Add a Not Null Column Without Default Value
Selecting Rows Where Remainder (Modulo) Is 1 After Division by 2
Alter Database Failed Because a Lock Could Not Be Placed on Database
Standard Use of 'Z' Instead of Null to Represent Missing Data
How to Insert Multiple Rows into Oracle with a Sequence Value
Database/SQL Tx - Detecting Commit or Rollback
Difference Between Drop Table and Truncate Table
Difference Between for and After Triggers
Tricks for Generating SQL Statements in Excel
SQL Server Script to Create a New User
How to Drop Table Variables in SQL-Server? Should I Even Do This
Query to Check Index on a Table
Unwrap Postgresql Array into Rows
How to Detect If a Stored Procedure Already Exists
How to Use a Postgresql Triggers to Store Changes (SQL Statements and Row Changes)