summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stf/CCustomLogger.py
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-03-30 11:29:11 +0300
committerYaroslav Brustinov <ybrustin@cisco.com>2016-03-30 11:29:11 +0300
commitb91c216db1aa10ca7cc81b8c74b04ab79df251fe (patch)
treebd2184c2ea54c2e8d6554e082dd0b37e99a1e0e7 /scripts/automation/trex_control_plane/stf/CCustomLogger.py
parent935b711d82845514c30249b8cdd2e9ed6aa11526 (diff)
add to run_functional_tests --python2 and --python3 flags
make stateful tree similar to stl : stf/trex_stf_lib and stf/examples change trex_client package: add profiles, use full stl dir. stl examples: now use stl_path.STL_PROFILES_PATH variable regression: add higher timeout to rsync.
Diffstat (limited to 'scripts/automation/trex_control_plane/stf/CCustomLogger.py')
-rwxr-xr-xscripts/automation/trex_control_plane/stf/CCustomLogger.py100
1 files changed, 0 insertions, 100 deletions
diff --git a/scripts/automation/trex_control_plane/stf/CCustomLogger.py b/scripts/automation/trex_control_plane/stf/CCustomLogger.py
deleted file mode 100755
index ecf7d519..00000000
--- a/scripts/automation/trex_control_plane/stf/CCustomLogger.py
+++ /dev/null
@@ -1,100 +0,0 @@
-
-import sys
-import os
-import logging
-
-
-def setup_custom_logger(name, log_path = None):
- # first make sure path availabe
-# if log_path is None:
-# log_path = os.getcwd()+'/trex_log.log'
-# else:
-# directory = os.path.dirname(log_path)
-# if not os.path.exists(directory):
-# os.makedirs(directory)
- logging.basicConfig(level = logging.INFO,
- format = '%(asctime)s %(name)-10s %(module)-20s %(levelname)-8s %(message)s',
- datefmt = '%m-%d %H:%M')
-# filename= log_path,
-# filemode= 'w')
-#
-# # define a Handler which writes INFO messages or higher to the sys.stderr
-# consoleLogger = logging.StreamHandler()
-# consoleLogger.setLevel(logging.ERROR)
-# # set a format which is simpler for console use
-# formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
-# # tell the handler to use this format
-# consoleLogger.setFormatter(formatter)
-#
-# # add the handler to the logger
-# logging.getLogger(name).addHandler(consoleLogger)
-
-def setup_daemon_logger (name, log_path = None):
- # first make sure path availabe
- logging.basicConfig(level = logging.INFO,
- format = '%(asctime)s %(name)-10s %(module)-20s %(levelname)-8s %(message)s',
- datefmt = '%m-%d %H:%M',
- filename= log_path,
- filemode= 'w')
-
-class CustomLogger(object):
-
- def __init__(self, log_filename):
- # Store the original stdout and stderr
- sys.stdout.flush()
- sys.stderr.flush()
-
- self.stdout_fd = os.dup(sys.stdout.fileno())
- self.devnull = os.open('/dev/null', os.O_WRONLY)
- self.log_file = open(log_filename, 'w')
- self.silenced = False
- self.pending_log_file_prints = 0
-
- # silence all prints from stdout
- def silence(self):
- os.dup2(self.devnull, sys.stdout.fileno())
- self.silenced = True
-
- # restore stdout status
- def restore(self):
- sys.stdout.flush()
- sys.stderr.flush()
- # Restore normal stdout
- os.dup2(self.stdout_fd, sys.stdout.fileno())
- self.silenced = False
-
- #print a message to the log (both stdout / log file)
- def log(self, text, force = False, newline = True):
- self.log_file.write((text + "\n") if newline else text)
- self.pending_log_file_prints += 1
-
- if (self.pending_log_file_prints >= 10):
- self.log_file.flush()
- self.pending_log_file_prints = 0
-
- self.console(text, force, newline)
-
- # print a message to the console alone
- def console(self, text, force = False, newline = True):
- _text = (text + "\n") if newline else text
- # if we are silenced and not forced - go home
- if self.silenced and not force:
- return
-
- if self.silenced:
- os.write(self.stdout_fd, _text)
- else:
- sys.stdout.write(_text)
-
- sys.stdout.flush()
-
- # flush
- def flush(self):
- sys.stdout.flush()
- self.log_file.flush()
-
- def __exit__(self, type, value, traceback):
- sys.stdout.flush()
- self.log_file.flush()
- os.close(self.devnull)
- os.close(self.log_file)