]> git.parisson.com Git - teleforma.git/commitdiff
add logger
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 20 Nov 2023 11:12:00 +0000 (12:12 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 20 Nov 2023 11:12:00 +0000 (12:12 +0100)
teleforma/management/commands/teleforma-reset-all-passwords-with-mail-ae.py

index d0437343cec47fa866a763f025b4c92e5328fdb4..327957164188c114dcbf031d6fa32a89bcd65dcc 100644 (file)
@@ -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)