Configuring Detex¶
This section is intended to introduce the detex logger, show how to find the version of detex you are using, as well as present some package level variables that can be set.
The log¶
Detex can create a log of nearly everything it does, but this feature needs to be enabled.
First, we import detex
import detex
detex.setLogger()
(<logging.Logger at 0x7fdc65918190>,
'/home/derrick/Gits/detex/Tutorial/Advanced/Logging/detex_log.log')
Notice that, in your current working directory, a new file has been created called detex_log.log. Alternatively we could pass a relative or absolute path to the setLogger call to make the file in a different location and call it by a different name, but we will stick with the default for now.
For each logged event, that is each entry in the log, there are four fields separated by tabs (“\t”). They are:
- The date and time the entry was made
- The module that made the entry
- The level of the log, they are:
- info - nothing is wrong, detex is simply letting you know what it is doing.
- debug - there might be some minor problems, info is logged to help you figure it out.
- warning - something went wrong but detex can press forward. This happens, for example when detex finds corrupted data; it will issue a warning and try to move on to the next usable data block.
- critical - something is very wrong but detex will try to keep going (not used very often).
- error - detex encountered a major problem that cannot be ignored. At this point an exception is raised and everything stops.
- The message passed to the logger
Many times the logger will also print to the screen in addition to making an entry in the log file. If you prefer your screen not to be cluttered but detex you can silence it by setting the verbose variable to False.
detex.verbose = False
Detex also has a max file size the log can be. If it finds a log that has exceeded this size it will simply delete it and create a new one. Ideally, a rotating file handler will be used in the future to keep the log under the specified limit without deleting the whole log but as of version 1.0.4 it has not been implemented. The log size limit is controlled by the maxSize parameter which, by default is 10 mb.
One way to read a log, and process it in a systemic way is to use a function in the detex utilities called readLog, which will load the log into a pandas DataFrame (if you don’t know what that is stop and do the 10 minute tutorial on pandas). Once in a DataFrame you could search the log for certain times, levels, or strings in the messages. Of course, you could do this with commands like grep from a terminal as well, but the less you have to leave python the better.
log = detex.util.readLog()
log
| Time | Mod | Level | Msg | |
|---|---|---|---|---|
| 0 | 2015-12-12 23:18:38,411 | detex | INFO | Starting logging, path to log file: /home/derr... |
| 1 | 2015-12-14 18:55:42,993 | detex | INFO | Starting logging, path to log file: /home/derr... |
Version¶
You can check the detex version with the version attribute of detex
detex.__version__
'1.0.5'