def test_sender_as_handler_static(self): """ Test that tries to check that Sender class can be used as a Handler through the static functions and related logs are send to remote server """ try: engine_config = {"address": self.server, "port": self.port, "key": self.key, "cert": self.cert, "chain": self.chain, "check_hostname": False, "verify_mode": CERT_NONE} con = Sender.for_logging(config=engine_config, tag=self.my_app, level=TEST_FACILITY) logger = get_log(name="DevoLogger2", handler=con, level=TEST_FACILITY) print("Testing logger info") logger.info("Testing Sender static handler functionality... " "INFO - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') print("Testing logger error") logger.error("Testing Sender static logging handler " "functionality... ERROR - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') print("Testing logger warning") logger.warning("Testing Sender static logging handler " "functionality... WARNING - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') print("Testing logger debug") logger.debug("Testing Sender static logging handler " "functionality... DEBUG - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') print("Testing logger critical") logger.critical("Testing Sender static logging handler " "functionality... CRITICAL - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') con.close() except Exception as error: self.fail("Problems with test: %s" % str(error))
def __init__(self, config=None, con_type=None, timeout=30, debug=False, logger=None): if config is None: raise DevoSenderException("Problems with args passed to Sender") self.timestart = time.time() if isinstance(config, (dict, Configuration)): timeout = config.get("timeout", timeout) debug = config.get("debug", debug) config = self._from_dict(config=config, con_type=con_type) logging.Handler.__init__(self) self.logger = logger if logger else \ get_log(handler=get_stream_handler( msg_format='%(asctime)s|%(levelname)s|Devo-Sender|%(message)s')) self.socket = None self._sender_config = config self.reconnection = 0 self.debug = debug self.socket_timeout = timeout self.socket_max_connection = 3600 * 1000 self.buffer = SenderBuffer() self.logging = {} if isinstance(config, SenderConfigSSL): self.__connect_ssl() if isinstance(config, SenderConfigTCP): self.__connect_tcp_socket()
def test_sender_as_handler(self): """ Test that tries to check that Sender class can be used as a Handler and related logs are send to remote server """ try: engine_config = SenderConfigSSL(address=(self.server, self.port), key=self.key, cert=self.cert, chain=self.chain, check_hostname=False, verify_mode=CERT_NONE) con = Sender.for_logging(config=engine_config, tag=self.my_app, level=TEST_FACILITY) logger = get_log(name="DevoLogger", handler=con, level=TEST_FACILITY) print("Testing logger info") logger.info("Testing Sender inherit logging handler functio" "nality... INFO - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') print("Testing logger error") logger.error("Testing Sender inherit logging handler function" "ality... ERROR - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') print("Testing logger warning") logger.warning("Testing Sender inherit logging handler functio" "nality... WARNING - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') print("Testing logger debug") logger.debug("Testing Sender inherit logging handler functiona" "lity... DEBUG - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') print("Testing logger critical") logger.critical("Testing Sender inherit logging handler functio" "nality... CRITICAL - log") data_received = con.socket.recv(5000) print(b"\n" + data_received) if len(data_received) == 0: raise Exception('Not msg sent!') con.close() except Exception as error: self.fail("Problems with test: %s" % str(error))
def test_sender_as_handler_static(self): """ Test that tries to check that Sender class can be used as a Handler through the static functions and related logs are send to remote server """ try: engine_config = { "address": self.server, "port": self.port, "key": self.key, "cert": self.cert, "chain": self.chain } con = Sender.for_logging(config=engine_config, tag=self.my_app) logger = get_log(name="DevoLogger2", handler=con) logger.info("Testing Sender static handler functionality... " "INFO - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') logger.error("Testing Sender static logging handler " "functionality... ERROR - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') logger.warning("Testing Sender static logging handler " "functionality... WARNING - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') logger.debug("Testing Sender static logging handler " "functionality... DEBUG - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') logger.critical("Testing Sender static logging handler " "functionality... CRITICAL - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') con.close() except Exception as error: self.fail("Problems with test: %s" % str(error))
def test_sender_as_handler(self): """ Test that tries to check that Sender class can be used as a Handler and related logs are send to remote server """ try: engine_config = SenderConfigSSL(address=(self.server, self.port), key=self.key, cert=self.cert, chain=self.chain) con = Sender.for_logging(config=engine_config, tag=self.my_app) logger = get_log(name="DevoLogger", handler=con) logger.info("Testing Sender inherit logging handler functio" "nality... INFO - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') logger.error("Testing Sender inherit logging handler function" "ality... ERROR - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') logger.warning("Testing Sender inherit logging handler functio" "nality... WARNING - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') logger.debug("Testing Sender inherit logging handler functiona" "lity... DEBUG - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') logger.critical("Testing Sender inherit logging handler functio" "nality... CRITICAL - log") if len(con.socket.recv(5000)) == 0: raise Exception('Not msg sent!') con.close() except Exception as error: self.fail("Problems with test: %s" % str(error))