[sqlalchemy] Re: Saving all transactions against a database (logging queries?)

2007-01-09 Thread Brian Jarrett

Jose,

Try it without the level=, format=, and datefmt= options in
logging.basicConfig() (leaving in only filename= and filemode=) and I
think it'll work.  Then you can try adding in the other options one at
a time and see if you can get them to work.  When I only had filename
and filemode specified, things worked.  Once I started adding more
parameters, I had similar problems.

Brian

On 1/6/07, jose <[EMAIL PROTECTED]> wrote:
>
> Hello Barry,
>
> I'm trying to get logging work...I put in my model.py the following code
> and I expected to see my queries into /tmp/sa.log file, but...
> what's wrong with it?
>
>
> from turbogears import database
> from sqlalchemy import Table, relation
> from sqlalchemy.engine import create_engine
> from sqlalchemy.ext.assignmapper import assign_mapper
> import logging
> database.bind_meta_data()
> session = database.session
> engine = database.metadata.engine
> context = session.context
> engine.echo = False
> logging.basicConfig(level=logging.DEBUG,
> format='%(asctime)s %(levelname)-8s %(message)s',
> datefmt='%a, %d %b %Y %H:%M:%S',
> filename='/tmp/sa.log',
> filemode='w')
> logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)·
>
>
> Barry Warsaw wrote:
>
> >
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA1
> >
> > On Jan 5, 2007, at 12:01 PM, Michael Bayer wrote:
> >
> >>
> >> i havent gotten around to adding docs for logging to the main
> >> docs...but its using Python's logging module now.  turn off all the
> >> "echo=True" flags and go straight to logging:
> >>
> >> import logging
> >> logging.basicConfig()  # see python's logging docs for options
> >> logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
> >
> >
> > Sweet.
> > - -Barry
> >
> > -BEGIN PGP SIGNATURE-
> > Version: GnuPG v1.4.5 (Darwin)
> >
> > iQCVAwUBRZ6IsnEjvBPtnXfVAQLINgP+JUdkjNn+CtAA5Uao3Gs+n+4IuuMeiCoz
> > 8J9yY9XlU74AW4N1ysf0wao0r2p871t2+sgIuFnBpRxO3DficR+iji3LJ24ZeWdH
> > KcG/uxUGk4uF7jfMeAdzVVRe/XqVRwI1uwMCN5p2rkXjdEokJp7G8uT872nC7EM5
> > 3OzCHKORs2M=
> > =PBfM
> > -END PGP SIGNATURE-
> >
> > >
>
>
> >
>

--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Saving all transactions against a database (logging queries?)

2007-01-05 Thread jose


Hello Barry,

I'm trying to get logging work...I put in my model.py the following code 
and I expected to see my queries into /tmp/sa.log file, but...

what's wrong with it?


from turbogears import database
from sqlalchemy import Table, relation
from sqlalchemy.engine import create_engine
from sqlalchemy.ext.assignmapper import assign_mapper
import logging
database.bind_meta_data()
session = database.session
engine = database.metadata.engine
context = session.context
engine.echo = False
logging.basicConfig(level=logging.DEBUG,
   format='%(asctime)s %(levelname)-8s %(message)s',
   datefmt='%a, %d %b %Y %H:%M:%S',
   filename='/tmp/sa.log',
   filemode='w')
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)·


Barry Warsaw wrote:



-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Jan 5, 2007, at 12:01 PM, Michael Bayer wrote:



i havent gotten around to adding docs for logging to the main
docs...but its using Python's logging module now.  turn off all the
"echo=True" flags and go straight to logging:

import logging
logging.basicConfig()  # see python's logging docs for options
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)



Sweet.
- -Barry

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRZ6IsnEjvBPtnXfVAQLINgP+JUdkjNn+CtAA5Uao3Gs+n+4IuuMeiCoz
8J9yY9XlU74AW4N1ysf0wao0r2p871t2+sgIuFnBpRxO3DficR+iji3LJ24ZeWdH
KcG/uxUGk4uF7jfMeAdzVVRe/XqVRwI1uwMCN5p2rkXjdEokJp7G8uT872nC7EM5
3OzCHKORs2M=
=PBfM
-END PGP SIGNATURE-

>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Saving all transactions against a database (logging queries?)

2007-01-05 Thread Brian Jarrett


Ahhh, that explains it.  In my example, I had already removed the crud
at the beginning of each line.

For anyone else looking to do something similar, you can configure
postgres.conf to log the queries it recieves and I get the following
in the log file
:
LOG:  statement: UPDATE students SET custom_20004='17-JAN-85'
WHERE students.student_id = 514

I'll still have to trim the beginning of each line, but it's usable.
Thanks for the help.

Brian


On 1/5/07, Michael Bayer <[EMAIL PROTECTED]> wrote:


every other line is a repr() of the bind parameter dictionary sent to
the query, so you probably want to grab those separately (they are sent
as distinct log lines - not sure why they are munged together in your
example above).  the query itself is using bind parameters in
psycopg2's configured bind param format, "pyformat".  thats what SA is
sending to the database.


>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Saving all transactions against a database (logging queries?)

2007-01-05 Thread Michael Bayer


every other line is a repr() of the bind parameter dictionary sent to
the query, so you probably want to grab those separately (they are sent
as distinct log lines - not sure why they are munged together in your
example above).  the query itself is using bind parameters in
psycopg2's configured bind param format, "pyformat".  thats what SA is
sending to the database.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Saving all transactions against a database (logging queries?)

2007-01-05 Thread Brian Jarrett


OK, I've got the logging working.  The INFO level gives much more than
just the actual queries run against the db, but the bigger problem is
that the queries aren't given in valid SQL.

Example from the log:

UPDATE students SET custom_20004=%(custom_20004)s WHERE
students.student_id = %(students_student_id)s {'custom_20004':
"'17-JAN-85'", 'students_student_id': Decimal("514")}

Is there any quick way to get it to output valid SQL?  I'm using
postgres, so I'm now looking at the possiblity it logging the queries
it receives instead.

Brian


On 1/5/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
> i havent gotten around to adding docs for logging to the main
> docs...but its using Python's logging module now.  turn off all the
> "echo=True" flags and go straight to logging:
>
> import logging
> logging.basicConfig()  # see python's logging docs for options
> logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
>
> the INFO level on 'sqlalchemy.engine' will give you all the queries,
> the DEBUG level the queries as well as the result sets.  using
> "logging" you can format the log messages any way you want and pass
> your own buffers in...just read the docs at
> http://www.python.org/doc/2.4.2/lib/module-logging.html .
>
>
> > >
>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Saving all transactions against a database (logging queries?)

2007-01-05 Thread Brian Jarrett


Excellent.  Thank you for the clarification.

Brian

On 1/5/07, Michael Bayer <[EMAIL PROTECTED]> wrote:


i havent gotten around to adding docs for logging to the main
docs...but its using Python's logging module now.  turn off all the
"echo=True" flags and go straight to logging:

import logging
logging.basicConfig()  # see python's logging docs for options
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

the INFO level on 'sqlalchemy.engine' will give you all the queries,
the DEBUG level the queries as well as the result sets.  using
"logging" you can format the log messages any way you want and pass
your own buffers in...just read the docs at
http://www.python.org/doc/2.4.2/lib/module-logging.html .


>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Saving all transactions against a database (logging queries?)

2007-01-05 Thread Barry Warsaw


-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Jan 5, 2007, at 12:01 PM, Michael Bayer wrote:



i havent gotten around to adding docs for logging to the main
docs...but its using Python's logging module now.  turn off all the
"echo=True" flags and go straight to logging:

import logging
logging.basicConfig()  # see python's logging docs for options
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)


Sweet.
- -Barry

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRZ6IsnEjvBPtnXfVAQLINgP+JUdkjNn+CtAA5Uao3Gs+n+4IuuMeiCoz
8J9yY9XlU74AW4N1ysf0wao0r2p871t2+sgIuFnBpRxO3DficR+iji3LJ24ZeWdH
KcG/uxUGk4uF7jfMeAdzVVRe/XqVRwI1uwMCN5p2rkXjdEokJp7G8uT872nC7EM5
3OzCHKORs2M=
=PBfM
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Saving all transactions against a database (logging queries?)

2007-01-05 Thread Michael Bayer


i havent gotten around to adding docs for logging to the main
docs...but its using Python's logging module now.  turn off all the
"echo=True" flags and go straight to logging:

import logging
logging.basicConfig()  # see python's logging docs for options
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

the INFO level on 'sqlalchemy.engine' will give you all the queries,
the DEBUG level the queries as well as the result sets.  using
"logging" you can format the log messages any way you want and pass
your own buffers in...just read the docs at
http://www.python.org/doc/2.4.2/lib/module-logging.html .


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---