summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/Logger.py55
-rw-r--r--src/lib/Server/Plugins/Cfg.py2
2 files changed, 56 insertions, 1 deletions
diff --git a/src/lib/Logger.py b/src/lib/Logger.py
index b9b4679bb..bb3c703a6 100644
--- a/src/lib/Logger.py
+++ b/src/lib/Logger.py
@@ -158,3 +158,58 @@ def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='da
logging.root.addHandler(filelog)
logging.root.setLevel(level)
logging.already_setup = True
+
+def trace_process (**kwargs):
+
+ """Literally log every line of python code as it runs.
+
+ Keyword arguments:
+ log -- file (name) to log to (default stderr)
+ scope -- base scope to log to (default Cobalt)"""
+
+ file_name = kwargs.get("log", None)
+ if file_name is not None:
+ log_file = open(file_name, "w")
+ else:
+ log_file = sys.stderr
+
+ scope = kwargs.get("scope", "Cobalt")
+
+ def traceit (frame, event, arg):
+ if event == "line":
+ lineno = frame.f_lineno
+ filename = frame.f_globals["__file__"]
+ if (filename.endswith(".pyc") or
+ filename.endswith(".pyo")):
+ filename = filename[:-1]
+ name = frame.f_globals["__name__"]
+ line = linecache.getline(filename, lineno)
+ print >> log_file, "%s:%s: %s" % (name, lineno, line.rstrip())
+ return traceit
+
+ sys.settrace(traceit)
+
+def log_to_stderr (logger_name, level=logging.INFO):
+ """Set up console logging."""
+ try:
+ logger = logging.getLogger(logger_name)
+ except:
+ # assume logger_name is already a logger
+ logger = logger_name
+ handler = logging.StreamHandler() # sys.stderr is the default stream
+ handler.setLevel(level)
+ handler.setFormatter(TermiosFormatter()) # investigate this formatter
+ logger.addHandler(handler)
+
+def log_to_syslog (logger_name, level=logging.INFO, format='%(name)s[%(process)d]: %(message)s'):
+ """Set up syslog logging."""
+ try:
+ logger = logging.getLogger(logger_name)
+ except:
+ # assume logger_name is already a logger
+ logger = logger_name
+ # anticipate an exception somewhere below
+ handler = logging.handlers.SysLogHandler() # investigate FragmentingSysLogHandler
+ handler.setLevel(level)
+ handler.setFormatter(logging.Formatter(format))
+ logger.addHandler(handler)
diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py
index f1c2a605f..3a4341e73 100644
--- a/src/lib/Server/Plugins/Cfg.py
+++ b/src/lib/Server/Plugins/Cfg.py
@@ -18,7 +18,7 @@ def process_delta(data, delta):
elif line[0] == '-':
if line[1:] in datalines:
datalines.remove(line[1:])
- return "\n".join(datalines) + "\n"
+ return "\n".join(datalines)
elif delta.op == 'diff':
basefile = open(tempfile.mktemp(), 'w')
basefile.write(data)