Skip to content
Snippets Groups Projects
Commit 34de0c0d authored by jkerdreu's avatar jkerdreu
Browse files

New config / logging

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@2069 b32b6428-25c9-4566-ad07-03861ab6144f
parent 461e2ec6
No related branches found
No related tags found
No related merge requests found
......@@ -8,13 +8,13 @@ from configobj import ConfigObj
self = sys.modules[__name__]
# Default settings
DEF_ADDR = '224.0.29.200' # mcast address
DEF_PORT = 1235 # mcast port
DEF_HOPS = 10 # mcast hop
DEF_ALIVE_TIMER = 100 # Time between two alive msg
DEF_CIPHER_WINDOW = 60 * 2 # Time Window in seconds to avoid replay attacks
DEF_ADDR = '224.0.29.200' # mcast address
DEF_PORT = 1235 # mcast port
DEF_HOPS = 10 # mcast hop
DEF_ALIVE_TIMER = 100 # Time between two alive msg
DEF_CIPHER_WINDOW = 60 * 2 # Time Window in seconds to avoid replay attacks
DEF_LOG_LEVEL = 'DEBUG' # should be INFO|DEBUG|None
DEF_LOG_PATH = '/var/log/xaal' # where log are
# TBD : Move this stuff
STACK_VERSION = '0.5'
......@@ -39,6 +39,8 @@ def load_config(name='xaal.ini'):
self.hops = int(cfg.get('hops',DEF_HOPS))
self.alive_timer = int(cfg.get('alive_timer',DEF_ALIVE_TIMER))
self.cipher_window = int(cfg.get('ciper_window',DEF_CIPHER_WINDOW))
self.log_level = cfg.get('address',DEF_LOG_LEVEL)
self.log_path = cfg.get('address',DEF_LOG_PATH)
key = cfg.get('key',None)
if key:
......
......@@ -26,9 +26,6 @@ import re
import pysodium
import logging
import logging.config
import sys
from configobj import ConfigObj
......@@ -42,7 +39,6 @@ def get_cfg_filename(name, cfg_dir=config.conf_dir):
if not os.path.isdir(cfg_dir):
print("Your configuration directory doesn't exist: [%s]" % cfg_dir)
return os.path.join(cfg_dir, filename)
def load_cfg_file(filename):
""" load .ini file and return it as dict"""
......@@ -83,31 +79,6 @@ def is_valid_devtype(val):
return True
return False
def get_logger(name, level, filename=None):
""" It creates logger if doesn't exist.
- Default handler is in the console with DEBUG level.
- A second handler (Rotating file handler) is created if a
filename is specified with INFO level
"""
logger = logging.getLogger(name)
# define handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(formatter)
logger.root.addHandler(console_handler)
if filename:
file_handler = logging.handlers.RotatingFileHandler(filename, 'a', 10000, 1, 'utf8')
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter)
logger.root.addHandler(file_handler)
# Level manage by the root logger
logger.root.setLevel(level)
return logger
def pass2key(passphrase):
"""Generate key from passphrase using libsodium
crypto_pwhash_scryptsalsa208sha256 func
......@@ -126,14 +97,12 @@ def pass2key(passphrase):
key = pysodium.crypto_pwhash_scryptsalsa208sha256(KEY_BYTES, buf, salt, opslimit, memlimit)
return key
def singleton(class_):
instances = {}
def getinstance(*args, **kwargs):
if class_ not in instances:
instances[class_] = class_(*args, **kwargs)
return instances[class_]
return getinstance
def reduce_addr(addr):
"""return a string based addred without all digits"""
return addr[:5] + '..' + addr[-5:]
def get_logger(name,level,filename=None):
print("!!!!!!!!!!!! PLEASE DONT USE get_logger ANYMORE !!!!!!!!!!!!!")
import logging
logging.basicConfig(level=level)
return logging.getLogger(name)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment