Commit 0bca814d authored by Juraj Sloboda's avatar Juraj Sloboda Committed by Matej Feder

Implement logging

parent c2442ed1
......@@ -4,3 +4,6 @@
__pycache__
*.swp
*.egg-info
# Log files
*.log
......@@ -8,7 +8,7 @@ from pydtn import start as bp_start
from pydtn_rest import start as rest_start
logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', level=logging.DEBUG)
logging.basicConfig(format='%(asctime)s - [%(name)s] - [%(levelname)-5s] - %(message)s', level=logging.DEBUG)
our_eid = None
......
import asyncio
import logging
import logging.config
import pkg_resources
import yaml
from .bundle_protocol import bp_agent
from .bundle_protocol.bp_node import set_bp_node_id
from .bundle_protocol.convergence_layers.tcp_cl import TCPCLAdapter
logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', level=logging.DEBUG)
def load_config():
filename = pkg_resources.resource_filename('pydtn', 'pydtn.yaml')
with open(filename, 'rt') as file:
config = yaml.safe_load(file.read())
return config
def start(node_id, tcp_port):
def start(node_id, tcp_port, config=load_config()):
logging.config.dictConfig(config['log'])
set_bp_node_id(node_id)
# Initialize TCP convergence layer adapter
......
# === LOGGING ===
log:
version: 1
formatters:
standard:
format: "%(asctime)s - [%(name)s] - [%(levelname)-5s] - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: standard
stream: ext://sys.stdout
file:
class: logging.handlers.WatchedFileHandler
level: DEBUG
formatter: standard
filename: pydtn.log
root:
level: DEBUG
handlers: [console, file]
loggers:
pydtn:
level: DEBUG
handlers: [console, file]
propogate: no
pyyaml~=3.13
cbor~=1.0.0
cbor2~=4.1.2
asyncio~=3.4.3
......@@ -2,6 +2,7 @@ from setuptools import setup, find_packages
install_requires = [
'pyyaml>=3.13',
'cbor>=1.0.0',
'cbor2>=4.1.2',
'asyncio>=3.4.3',
......
import logging
import logging.config
from aiohttp import web
import pkg_resources
import yaml
from pydtn.bundle_protocol import bp_agent
from pydtn.bundle_protocol.bp_node import get_bp_node_id
logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', level=logging.DEBUG)
def load_config():
filename = pkg_resources.resource_filename('pydtn_rest', 'pydtn_rest.yaml')
with open(filename, 'rt') as file:
config = yaml.safe_load(file.read())
return config
our_eid = None
......@@ -47,7 +54,9 @@ async def handle_bundle(request):
return web.json_response({'success': True})
def start(port, host='0.0.0.0'):
def start(port, host='0.0.0.0', config=load_config()):
logging.config.dictConfig(config['log'])
global bp_client, our_eid
our_eid = f'{get_bp_node_id()}/web'
bp_client = bp_agent.register(our_eid, None)
......
# === LOGGING ===
log:
version: 1
formatters:
standard:
format: "%(asctime)s - [%(name)s] - [%(levelname)-5s] - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: standard
stream: ext://sys.stdout
file:
class: logging.handlers.WatchedFileHandler
level: DEBUG
formatter: standard
filename: pydtn_rest.log
root:
level: DEBUG
handlers: [console, file]
loggers:
pydtn_rest:
level: DEBUG
handlers: [console, file]
propogate: no
pyyaml~=3.13
pydtn~=1.0.0
aiohttp~=3.5.4
......@@ -2,6 +2,7 @@ from setuptools import setup, find_packages
install_requires = [
'pyyaml>=3.13',
'pydtn>=1.0.0',
'aiohttp>=3.5.4',
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment