diff --git a/ArchiveExtractor.py b/ArchiveExtractor.py
index 44a3c903dd69ea2acc0a99018e333145e281b200..1e4fef8e6f391adc11fada4ed11da6f7a2765614 100755
--- a/ArchiveExtractor.py
+++ b/ArchiveExtractor.py
@@ -12,8 +12,6 @@ import numpy as np
 import PyTango as tango
 
 
-# Name the logger after the filename
-logger = logging.getLogger("ArchiveExtractor")
 
 ##########################################################################
 """ Commodity variables """
@@ -260,6 +258,8 @@ def query_ADB_NearestValue(attr,
 """ Command Line Interface """
 if __name__ == "__main__":
 
+    # Name the logger after the filename
+    logger = logging.getLogger("ArchiveExtractor")
 
     # Default stop date
     dateStop = datetime.datetime.now()
@@ -347,3 +347,7 @@ if __name__ == "__main__":
         # Save all at each step
         np.save(args.fileout, results)
 
+
+else:
+    # Name the logger after the module name
+    logger = logging.getLogger(__name__)