Modify ↓
Ticket #178 (assigned defect)
Add logging to db commands (and possibly ORM)
| Reported by: | andrew | Owned by: | andrew |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.0 |
| Component: | databaseapi | Version: | 0.6-pre |
| Keywords: | Cc: |
Description
Suggested by #176 initially; all SQL from db commands should be logged to a text file, possibly capturing ORM ones too if possible.
Attachments
Change History
comment:1 Changed 4 years ago by andrew
- Status changed from new to assigned
- Component changed from commands to databaseapi
comment:2 Changed 4 years ago by Robert <trebor74hr@…>
There is also an issue of overlogging, e.g. if someone uses code like this:
# code is just for demonstration
for person in Person.objects.all():
person.first_name, person.last_name = person.name.split()
person.save() # sql update to db
self.commit()
If each .save() creates one or two log entries, and we need to migrate 100.000 records. In this case probably logging looses purpose.
Currently I can see two possible solutions:
- execute, orm actions, etc. and any method that can cause overlogging problem shouldn't be logged at all or logged only for first N calls per migration?!
- and/or user can explicitelly turn off default logging level in such cases and call explicitelly self.log whenever it is needed (user decides)
Considering this, code could be changed (code is just for demonstration):
self.setloglevel(level=3) # e.g. 4 is maximum
for i, person in enumerate(Person.objects.all()):
person.first_name, person.last_name = person.name.split()
person.save() # sql update to db
if i%500:
self.log("commited %d persons' update of fn/ln" % i)
self.commit()
self.commit()
self.setloglevel(level=4)
Note: See
TracTickets for help on using
tickets.
