From: Guillaume Pellerin Date: Mon, 20 Nov 2023 11:12:00 +0000 (+0100) Subject: add logger X-Git-Tag: 2.8.1-ae~21 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=a6d006e8a396c678b724d3e032402178d1f23238;p=teleforma.git add logger --- diff --git a/teleforma/management/commands/teleforma-reset-all-passwords-with-mail-ae.py b/teleforma/management/commands/teleforma-reset-all-passwords-with-mail-ae.py index d0437343..32795716 100644 --- a/teleforma/management/commands/teleforma-reset-all-passwords-with-mail-ae.py +++ b/teleforma/management/commands/teleforma-reset-all-passwords-with-mail-ae.py @@ -15,6 +15,18 @@ import logging from postman import * +class Logger: + """A logging object""" + + def __init__(self, file): + self.logger = logging.getLogger('myapp') + self.hdlr = logging.FileHandler(file) + self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') + self.hdlr.setFormatter(self.formatter) + self.logger.addHandler(self.hdlr) + self.logger.setLevel(logging.INFO) + + class Command(BaseCommand): help = "Reset the password for all (active) users " message_template = 'postman/email_user_init.txt' @@ -30,6 +42,9 @@ class Command(BaseCommand): send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False) def handle(self, *args, **options): + log_file = args[-1] + logger = Logger(log_file) + users = User.objects.all() translation.activate(self.language_code) for user in users: @@ -42,5 +57,4 @@ class Command(BaseCommand): self.init_password_email(user) profile.init_password = True profile.save() - print user.username - + logger.logger.info(user.username)