Skip to content

Commit

Permalink
Merge pull request #19 from percival-detector/dev
Browse files Browse the repository at this point in the history
Improved logging.
  • Loading branch information
ajgdls committed Aug 3, 2017
2 parents 8191755 + 0f7a6c1 commit a73ff03
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
6 changes: 5 additions & 1 deletion percival/carrier/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,15 @@ def __getattr__(self, item):
def get_ini_file(self, item):
if "Configuration" not in self.conf.sections():
raise_with_traceback(RuntimeError("Configuration section not found in ini file %s" % str(self._ini_filename)))
return self.conf.get("Configuration", item).strip("\"")
value = self.conf.get("Configuration", item).strip("\"")
self.log.debug("Checking for %s in percival control config file. Value: %s", item, value)
return value

def get_ini_file_download(self, item):
if "Configuration" not in self.conf.sections():
raise_with_traceback(RuntimeError("Configuration section not found in ini file %s" % str(self._ini_filename)))
value = self.conf.get("Configuration", item).strip("\"")
self.log.debug("Checking for %s in percival control config file. Raw value: %s", item, value)
if isinstance(value, str):
if 'false' in value.lower():
value = False
Expand All @@ -490,6 +493,7 @@ def get_ini_file_download(self, item):
else:
value = bool(value)

self.log.debug(" Processed value: %s", value)
return value

@property
Expand Down
2 changes: 1 addition & 1 deletion percival/carrier/registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __getattr__(self, name):
raise_with_traceback(AttributeError("No attribute: %s"%name))

def __setattr__(self, name, value):
logger.debug(str(self._mem_map))
#logger.debug(str(self._mem_map))
if name not in self._mem_map.keys():
return object.__setattr__(self, name, value)
else:
Expand Down
4 changes: 4 additions & 0 deletions percival/detector/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def command_type(self):
def command_name(self):
return self._command_name

@property
def command_time(self):
return self._trace[CommandTrace.creation_time]

@property
def format_trace(self):
return {'Username': self._trace[CommandTrace.user],
Expand Down
25 changes: 16 additions & 9 deletions percival/detector/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,20 +507,14 @@ class PercivalDetector(object):
def __init__(self, ini_file=None, download_config=True, initialise_hardware=True):
self._log = logging.getLogger(".".join([__name__, self.__class__.__name__]))
self._trace_log = logging.getLogger("percival_trace")
#self._trace_log = get_exclusive_file_logger('./logs/percival_trace_{}.log'.format(datetime.now()
# .isoformat()
# .replace(':', '_')
# .replace('-', '_')))
print(self._trace_log)
print(self._trace_log.getEffectiveLevel())
#self._trace_log.setLevel(20)
print(self._trace_log.getEffectiveLevel())
self._trace_log.info("Percival execution trace logging")
self._log.info("Executing detector constructor")
self._start_time = datetime.now()
self._username = getpass.getuser()
self._txrx = None
self._db = None
self._global_monitoring = False
self._log.info("Executing detector constructor")
self._percival_params = PercivalParameters(ini_file)
self._board_settings = {}
self._board_values ={}
Expand All @@ -531,19 +525,31 @@ def __init__(self, ini_file=None, download_config=True, initialise_hardware=True
self._sensor = None
self._control_groups = None
self._monitor_groups = None
self._log.info("Creating SystemSettings object")
self._system_settings = SystemSettings()
self._log.info("Creating ChipRadoutSettings object")
self._chip_readout_settings = ChipReadoutSettings()
self._log.info("Creating ClockSettings object")
self._clock_settings = ClockSettings()
self._log.info("Creating SetPointControl object")
self._setpoint_control = SetPointControl(self)
self._log.info("Starting setpoint control scan loop")
self._setpoint_control.start_scan_loop()
self._log.info("Calling load_ini for detector")
self.load_ini()
self._log.info("Setting up database connection to influxdb")
self.setup_db()
self._log.info("Setting up control interface")
self.setup_control()
self._log.info("Checking for auto-download of configuration files")
self.auto_download()
if download_config:
self._log.info("Loading channel configuration to hardware")
self.load_configuration()
self._log.info("Loading channel information from hardware shortcuts")
self.load_channels()
if initialise_hardware:
self._log.info("Executing initialisation of channels")
self.initialize_channels()

def cleanup(self):
Expand Down Expand Up @@ -791,7 +797,8 @@ def execute_command(self, command):
:param command:
:return:
"""
response = {}
response = {'command': command.command_name,
'time': command.command_time}
# Check if the command is a PUT command
if 'PUT' in command.command_type:
# Log the trace information from the command object
Expand Down
28 changes: 14 additions & 14 deletions percival/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
},
'log_file': {
'class': 'percival.mkdir_handler.MkDirRotatingFileHandler',
'formatter': 'simple',
'formatter': 'verbose',
'filename': './logs/percival.log', #.format(datetime.now()
# .isoformat()
# .replace(':', '_')
# .replace('-', '_')),
'maxBytes': 1048576,
'backupCount': 10
'maxBytes': 5242880,
'backupCount': 20
},
'trace_file': {
'class': 'percival.mkdir_handler.MkDirRotatingFileHandler',
Expand All @@ -37,8 +37,8 @@
# .isoformat()
# .replace(':', '_')
# .replace('-', '_')),
'maxBytes': 1048576,
'backupCount': 10
'maxBytes': 5242880,
'backupCount': 20
}
},
'loggers': {
Expand All @@ -55,11 +55,11 @@
'percival': {
'handlers': ['log_file'],
'propagate': False,
'level': 'ERROR',
'level': 'DEBUG',
},
'percival.carrier': {
'handlers': ['log_file'],
'level': 'ERROR',
'level': 'DEBUG',
'propagate': False,
},
'percival.carrier.simulator': {
Expand All @@ -69,22 +69,22 @@
},
'percival.carrier.system.SystemSettings': {
'handlers': ['log_file'],
'level': 'INFO',
'level': 'DEBUG',
'propagate': False,
},
'percival.carrier.sensor.Sensor': {
'handlers': ['log_file'],
'level': 'DEBUG',
'level': 'ERROR',
'propagate': False,
},
'percival.carrier.buffer': {
'handlers': ['log_file'],
'level': 'ERROR',
'level': 'DEBUG',
'propagate': False,
},
'percival.carrier.buffer.BufferCommand': {
'handlers': ['log_file'],
'level': 'ERROR',
'level': 'DEBUG',
'propagate': False,
},
'percival.carrier.channels': {
Expand Down Expand Up @@ -134,12 +134,12 @@
},
'percival.control': {
'handlers': ['log_file'],
'level': 'ERROR',
'level': 'DEBUG',
'propagate': False,
},
'percival.detector': {
'handlers': ['log_file'],
'level': 'ERROR',
'level': 'DEBUG',
'propagate': False,
},
'percival.detector.ipc_reactor.IpcReactor': {
Expand All @@ -164,7 +164,7 @@
},
'percival.detector.detector.PercivalDetector': {
'handlers': ['log_file'],
'level': 'ERROR',
'level': 'DEBUG',
'propagate': False,
},
'BoardSettings': {
Expand Down
12 changes: 12 additions & 0 deletions percival/mkdir_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,17 @@ def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None,
dir = os.path.dirname(filename)
if not os.path.exists(dir):
os.makedirs(dir)
self._clean_directory(filename)
RotatingFileHandler.__init__(self, filename, mode, maxBytes, backupCount, encoding, delay)

def _clean_directory(self, filename):
file = os.path.basename(filename)
directory = os.path.dirname(filename)
for the_file in os.listdir(directory):
if file in the_file:
file_path = os.path.join(directory, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as e:
print(e)

0 comments on commit a73ff03

Please sign in to comment.