Thanks for your answers.
I ended up doing as Michael suggested:
engine = create_engine(conn_string)
def before_cursor_execute(conn, cursor, statement, parameters,
context, executemany):
log.info(re.sub('[\r\n]', '', '{} - {}'.format(statement,
parameters)))
event.listen(engine, 'before_cursor_execute', before_cursor_execute)
On Wednesday, April 23, 2014 3:09:57 AM UTC+3, Joshua Ma wrote:
>
> One thing I like to do is grab the logger and just log my own line around
> the query:
>
> logger = logging.getLogger('sqlalchemy.engine')
> logger.info('========== ABOUT TO RUN MY QUERY ==========')
> # run your query
> logger.info('========== DONE RUNNING QUERY ==========')
>
> and then I grep the logs for "ABOUT TO RUN MY QUERY" instead. Doesn't
> answer your question of writing to a single line, but makes it easier to
> find at least.
>
> On Tuesday, April 22, 2014 1:29:41 PM UTC-7, Michael Bayer wrote:
>>
>> you can perhaps use a logging filter, just split the logs on a different
>> token other than the newline, or write your own log routine using the
>> before_cursor_execute event. there’s a lot of ways to get this effect but
>> none are more convenient than another.
>>
>>
>> On Apr 22, 2014, at 10:49 AM, lev katzav <[email protected]> wrote:
>>
>> Hi all,
>>
>> I am execution a complicated query,
>> and when the query is written to the log, it breaks down into separate
>> lines.
>>
>> This makes it really difficult to search the resulting log file for a
>> query,
>> since grep will find only part of the query.
>>
>> Is there a way to force the query to be written in a single line?
>>
>> Thanks,
>> Lev.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.