Code

Opened 5 months ago

Last modified 5 months ago

#21429 new New feature

BaseCommand should use logging instead of custom output wrappers

Reported by: Nical Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Normal Keywords: command output logger
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Since python offers the powerful logging class, django.core.management.base.BaseCommand should use it to output messages instead of using custom output wrappers (django.core.management.base.OutputWrapper).

Doing so, we could override those loggers in the settings.py file.

Instead of having two wrappers in a command and having to do:

class Command(BaseCommand):
  def handle(self):
    self.stdout.write('this is an info message')
    self.stderr.write('this is an error message')

We could do

class Command(BaseCommand):
  def handle(self):
    self.output.info('this is an info message')
    self.output.error('this is an error message')
    # and even
    self.output.warning('this is a warning message')

The style_func and ending arguments that the django.core.management.base.OutputWrapper.write method takes could be removed and be configured at once in a overriding custom logger.

Attachments (0)

Change History (1)

comment:1 Changed 5 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.6 to master

I worked on that idea in #15107 (that I just closed).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.