Commit 6dec8eaa authored by Dario Ernst's avatar Dario Ernst Committed by oroulet

Replace leftover prints with logging

In various places in the library, there were some print()s. These make
it hard to control the output of the library externally, e.g. when
supressing logging output for clean testing-logs.
This commit attempts to replace all leftover print()s by logging calls.
parent 56965b33
...@@ -21,7 +21,7 @@ use_crypto = True ...@@ -21,7 +21,7 @@ use_crypto = True
try: try:
from opcua.crypto import uacrypto from opcua.crypto import uacrypto
except ImportError: except ImportError:
print("cryptography is not installed, use of crypto disabled") logging.getLogger(__name__).warning("cryptography is not installed, use of crypto disabled")
use_crypto = False use_crypto = False
......
...@@ -7,6 +7,7 @@ for custom structures ...@@ -7,6 +7,7 @@ for custom structures
import os import os
import importlib import importlib
import re import re
import logging
# The next two imports are for generated code # The next two imports are for generated code
from datetime import datetime from datetime import datetime
import uuid import uuid
...@@ -229,7 +230,7 @@ def load_type_definitions(server, nodes=None): ...@@ -229,7 +230,7 @@ def load_type_definitions(server, nodes=None):
if ref_desc_list: #some server put extra things here if ref_desc_list: #some server put extra things here
name = _clean_name(ndesc.BrowseName.Name) name = _clean_name(ndesc.BrowseName.Name)
if not name in structs_dict: if not name in structs_dict:
print("Error {} is found as child of binary definition node but is not found in xml".format(name)) logging.getLogger(__name__).warning("Error {} is found as child of binary definition node but is not found in xml".format(name))
continue continue
nodeid = ref_desc_list[0].NodeId nodeid = ref_desc_list[0].NodeId
ua.register_extension_object(name, nodeid, structs_dict[name]) ua.register_extension_object(name, nodeid, structs_dict[name])
......
...@@ -113,7 +113,7 @@ class BinaryServer(object): ...@@ -113,7 +113,7 @@ class BinaryServer(object):
sockname = self._server.sockets[0].getsockname() sockname = self._server.sockets[0].getsockname()
self.hostname = sockname[0] self.hostname = sockname[0]
self.port = sockname[1] self.port = sockname[1]
print('Listening on {0}:{1}'.format(self.hostname, self.port)) self.logger.warning('Listening on {0}:{1}'.format(self.hostname, self.port))
def stop(self): def stop(self):
self.logger.info("Closing asyncio socket server") self.logger.info("Closing asyncio socket server")
......
...@@ -84,6 +84,7 @@ class HistoryDict(HistoryStorageInterface): ...@@ -84,6 +84,7 @@ class HistoryDict(HistoryStorageInterface):
self._datachanges_period = {} self._datachanges_period = {}
self._events = {} self._events = {}
self._events_periods = {} self._events_periods = {}
self.logger = logging.getLogger(__name__)
def new_historized_node(self, node_id, period, count=0): def new_historized_node(self, node_id, period, count=0):
if node_id in self._datachanges: if node_id in self._datachanges:
...@@ -105,7 +106,7 @@ class HistoryDict(HistoryStorageInterface): ...@@ -105,7 +106,7 @@ class HistoryDict(HistoryStorageInterface):
def read_node_history(self, node_id, start, end, nb_values): def read_node_history(self, node_id, start, end, nb_values):
cont = None cont = None
if node_id not in self._datachanges: if node_id not in self._datachanges:
print("Error attempt to read history for a node which is not historized") self.logger.warning("Error attempt to read history for a node which is not historized")
return [], cont return [], cont
else: else:
if start is None: if start is None:
......
...@@ -29,7 +29,7 @@ use_crypto = True ...@@ -29,7 +29,7 @@ use_crypto = True
try: try:
from opcua.crypto import uacrypto from opcua.crypto import uacrypto
except ImportError: except ImportError:
print("cryptography is not installed, use of crypto disabled") logging.getLogger(__name__).warning("cryptography is not installed, use of crypto disabled")
use_crypto = False use_crypto = False
......
...@@ -468,6 +468,6 @@ class UaProcessor(object): ...@@ -468,6 +468,6 @@ class UaProcessor(object):
to be called when client has disconnected to ensure we really close to be called when client has disconnected to ensure we really close
everything we should everything we should
""" """
print("Cleanup client connection: ", self.name) self.logger.info("Cleanup client connection: ", self.name)
if self.session: if self.session:
self.session.close_session(True) self.session.close_session(True)
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