Originally forked from BTS/Lightning on 05-Aug-2015.
(Originally forked from BTS/Lightning on 05-Aug-2015.)
---
### Quick start
1. git clone this, then run `python2.7 setup.py install --user`
2. in your top script, add the lines:
1.`import OperationalLogging as OpLog`
2.`OpLog.setup()` --- *this must come before your first call to `logging.basicConfig`*
That's all.
-----
### Detailed usage
(Not all of this has been tested yet.)
So long as you call `OperationalLogging.setup()` first, all subsequent `logging.basicConfig()`s in your code will be ignored. You only need to include `setup()` the once in your top-level script. Any logging calls deeper in your scripts should be handled by OpLog unless they explicitly provide a different logger name.
#### **Optional arguments to `setup()`**
*`config_file`: Filename of a .json file. It should contain a dict that will be read in as logging config using the keywords below. Any other arguments provided to `setup()` will override any options loaded from file.
*`logger_name`: Equivalent to using `getLogger(logger_name)`; the default of root/None is probably preferable.
*`log_filename`, `log_root_dir`: Log will be written to file at DEBUG level, saved as `LOG_ROOT_DIR/log/YYYY-MM-DD/log_filename.log`. `log_root_dir` defaults to current directory, and `log_filename` to scriptName.log.
*`from_address`: If email notifications are sent, this appears as the From field.
*`notify`: Dict containing lists of email addresses to notify at a given level, e.g. `{'ERROR': ['alice@example.com', 'bob@example.com'], 'CRITICAL': ['msze@aer.com']]}`. At first, email notification will only be (potentially) triggered on script exit.
*`log_level`: Overall log level lower bound. Strongly recommended to leave this at its default value of `logging.DEBUG`, so you have it all on disk.
*`console_level`: Log level for stdout if applicable. Defaults to `logging.INFO`.
*`log_format_file`, `date_format_file`: Equivalent to `fmt` and `datefmt` options as supplied to logging handler formatter, applies to the log file only.
*`log_format_console`, `date_format_console`: As above, but for stdout.
#### **log_shell()**
For logging `subprocess` calls, use: `OperationalLogging.log_shell(arg_list, **kwargs)`
In general, `OpLog.log_shell([args])` will behave like `subprocess.call([args])`. It routes stderr to stdout, and it will return the process's exit code. This actually calls `os.Popen` instead of `subprocess` which was necessary to get an unbuffered pipe to see console output in real time. Any extra arguments will be passed to `Popen`.
(This seems to be solid---even the multicore aggregation works.)
---
### Example output
Very much subject to change. The file output contains a little more info by default, e.g.
/usr/local/CentOS6/lib/python2.7/site-packages/pycrypto-2.6.1-py2.7-linux-x86_64.egg/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.