diff options
author | 2016-08-30 09:33:44 +0800 | |
---|---|---|
committer | 2016-08-30 09:34:46 +0800 | |
commit | 1b8e4ce12d749141581ca880a13a71314acbbf79 (patch) | |
tree | c4f5f125725b6a9de38de7ee5c044a799303e5fb /deploy/adapters/ansible/openstack_mitaka/roles/onos_cluster/files/setup_networks/log.py | |
parent | 0e622c06737e9da4a97ca86452b9ebc23e8a330b (diff) |
Modify sfc bug for ONOS
Change-Id: Ied71c7e57553a846241ec826c8607ac1bb84e1e9
Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'deploy/adapters/ansible/openstack_mitaka/roles/onos_cluster/files/setup_networks/log.py')
-rw-r--r-- | deploy/adapters/ansible/openstack_mitaka/roles/onos_cluster/files/setup_networks/log.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/deploy/adapters/ansible/openstack_mitaka/roles/onos_cluster/files/setup_networks/log.py b/deploy/adapters/ansible/openstack_mitaka/roles/onos_cluster/files/setup_networks/log.py new file mode 100644 index 00000000..fffeb589 --- /dev/null +++ b/deploy/adapters/ansible/openstack_mitaka/roles/onos_cluster/files/setup_networks/log.py @@ -0,0 +1,41 @@ +import logging +import os +loggers = {} +log_dir="/var/log/setup_network" +try: + os.makedirs(log_dir) +except: + pass + +def getLogger(name): + if name in loggers: + return loggers[name] + + logger = logging.getLogger(name) + logger.setLevel(logging.DEBUG) + + # create file handler which logs even debug messages + log_file = "%s/%s.log" % (log_dir, name) + try: + os.remove(log_file) + except: + pass + + fh = logging.FileHandler(log_file) + fh.setLevel(logging.DEBUG) + + # create console handler with a higher log level + ch = logging.StreamHandler() + ch.setLevel(logging.ERROR) + + # create formatter and add it to the handlers + formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + ch.setFormatter(formatter) + fh.setFormatter(formatter) + + # add the handlers to logger + logger.addHandler(ch) + logger.addHandler(fh) + + loggers[name] = logger + return logger |