Setup logging
This commit is contained in:
parent
8f38866761
commit
61cc924e56
@ -19,6 +19,7 @@ import triskele
|
||||
class AttributeProfiles(Filter):
|
||||
def __init__(self, area=None, sd=None, moi=None):
|
||||
super().__init__(self.__class__.__name__)
|
||||
self.logger.debug('Oh hi Mark!')
|
||||
self.area = np.sort(area) if area is not None else None
|
||||
self.sd = np.sort(sd) if sd is not None else None
|
||||
self.moi = np.sort(moi) if moi is not None else None
|
||||
|
||||
@ -14,4 +14,4 @@ from .Output import Output
|
||||
class Filter(Output, Input):
|
||||
"""Output should be first"""
|
||||
def __init__(self, name='__CHILD__'):
|
||||
super().__init__('Filter:{}'.format(name))
|
||||
super().__init__('F:{}'.format(name))
|
||||
|
||||
@ -12,7 +12,7 @@ from .Node import Node
|
||||
|
||||
class Input(Node):
|
||||
def __init__(self, name='__CHILD__'):
|
||||
super().__init__('Input:{}'.format(name))
|
||||
super().__init__('I:{}'.format(name))
|
||||
self.outputs = list()
|
||||
|
||||
def register(self, output):
|
||||
|
||||
@ -8,10 +8,12 @@
|
||||
#
|
||||
# TODO details
|
||||
|
||||
import logging
|
||||
|
||||
class Node(object):
|
||||
def __init__(self, name='A NODE HAS NO NAME'):
|
||||
self.name = name
|
||||
self.logger = logging.getLogger(name)
|
||||
|
||||
def __str__(self):
|
||||
return ("Node:{}".format(self.name))
|
||||
|
||||
@ -14,7 +14,7 @@ from .Input import Input
|
||||
|
||||
class Output(Node):
|
||||
def __init__(self, name='__CHILD__'):
|
||||
super().__init__('Output:{}'.format(name))
|
||||
super().__init__('O:{}'.format(name))
|
||||
self.__dict__['input'] = None
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
|
||||
50
ld2dap/core/logger.py
Normal file
50
ld2dap/core/logger.py
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file %filename%.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 24 avril 2018
|
||||
#
|
||||
# from https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/
|
||||
|
||||
import os
|
||||
import logging.config
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
def setup_logging(
|
||||
default_path='logging.yaml',
|
||||
default_level=logging.WARN,
|
||||
env_key='LOG_CFG'
|
||||
):
|
||||
"""Setup logging configuration
|
||||
|
||||
"""
|
||||
path = default_path
|
||||
value = os.getenv(env_key, None)
|
||||
if value:
|
||||
path = value
|
||||
if os.path.exists(path):
|
||||
with open(path, 'rt') as f:
|
||||
config = yaml.safe_load(f.read())
|
||||
makedirs(config)
|
||||
logging.config.dictConfig(config)
|
||||
else:
|
||||
logging.basicConfig(level=default_level)
|
||||
|
||||
def makedirs(dic):
|
||||
files = finddirs(dic)
|
||||
for f in files:
|
||||
d = Path(*f.parts[:-1])
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def finddirs(dic, key='filename'):
|
||||
r = list()
|
||||
value = dic.get(key)
|
||||
if value : r.append(Path(value))
|
||||
for k, v in dic.items():
|
||||
if isinstance(v, dict):
|
||||
r.extend(finddirs(v))
|
||||
return r
|
||||
40
logging.yaml
Normal file
40
logging.yaml
Normal file
@ -0,0 +1,40 @@
|
||||
version: 1
|
||||
disable_existing_loggers: False
|
||||
formatters:
|
||||
simple:
|
||||
format: "%(asctime)s %(levelname)s %(name)s: %(message)s"
|
||||
|
||||
handlers:
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
level: DEBUG
|
||||
formatter: simple
|
||||
stream: ext://sys.stdout
|
||||
|
||||
info_file_handler:
|
||||
class: logging.handlers.RotatingFileHandler
|
||||
level: INFO
|
||||
formatter: simple
|
||||
filename: Logs/info.log
|
||||
maxBytes: 10485760 # 10MB
|
||||
backupCount: 20
|
||||
encoding: utf8
|
||||
|
||||
error_file_handler:
|
||||
class: logging.handlers.RotatingFileHandler
|
||||
level: ERROR
|
||||
formatter: simple
|
||||
filename: Logs/errors.log
|
||||
maxBytes: 10485760 # 10MB
|
||||
backupCount: 20
|
||||
encoding: utf8
|
||||
|
||||
loggers:
|
||||
my_module:
|
||||
level: DEBUG
|
||||
handlers: [console]
|
||||
propagate: no
|
||||
|
||||
root:
|
||||
level: DEBUG
|
||||
handlers: [console, info_file_handler, error_file_handler]
|
||||
4
test.py
Normal file → Executable file
4
test.py
Normal file → Executable file
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/ipython
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file test.py
|
||||
# \brief TODO
|
||||
@ -11,10 +11,12 @@
|
||||
#from core import Input, Output, Filter
|
||||
from ld2dap import LoadTIFF, SaveFig, Treshold, ShowFig, Differential
|
||||
from ld2dap import AttributeProfiles as APs
|
||||
from ld2dap.core import logger
|
||||
|
||||
import numpy as np
|
||||
|
||||
def main():
|
||||
logger.setup_logging()
|
||||
i = LoadTIFF(['Data/test.tiff', 'Data/test2.tiff'])
|
||||
t = Treshold(1e4)
|
||||
ap = APs([100,1e3,1e4])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user