[Git][NTPsec/ntpsec][master] 2 commits: temp-log.py: remove obvious comment, fix typo

Gary E. Miller gitlab at mg.gitlab.com
Thu Jan 26 23:54:23 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
666469a4 by Gary E. Miller at 2017-01-26T13:53:07-08:00
temp-log.py: remove obvious comment, fix typo

- - - - -
ea39b014 by Gary E. Miller at 2017-01-26T15:53:40-08:00
temp-log.py: fix logging to file, remove redundant function.

- - - - -


1 changed file:

- contrib/temp-log.py


Changes:

=====================================
contrib/temp-log.py
=====================================
--- a/contrib/temp-log.py
+++ b/contrib/temp-log.py
@@ -8,6 +8,7 @@
 
 import argparse
 import logging
+import logging.handlers
 import os
 import re
 import subprocess
@@ -141,13 +142,18 @@ def logging_setup(fileName, logLevel):
     tempLogger = logging.getLogger()
     tempLogger.setLevel(logLevel)
     # Create file handler
-    _file = logging.handlers.TimedRotatingFileHandler(fileName,
-                                                      when='midnight',
-                                                      interval=1,
-                                                      backupCount=5,
-                                                      encoding=None,
-                                                      delay=False,
-                                                      utc=False)
+    if args.logfile:
+        _file = logging.handlers.TimedRotatingFileHandler(
+            fileName,
+            when='midnight',
+            interval=1,
+            backupCount=5,
+            encoding=None,
+            delay=False,
+            utc=False)
+    else:
+        _file = logging.StreamHandler(sys.stdout)
+
     _file.setLevel(logLevel)
     # Create the formatter and add it to the handler
     _file.setFormatter(logFormat)
@@ -205,8 +211,7 @@ def log_data():
     Logger = logging_setup(log, logging.INFO)
 
     # Create data layout
-    logData(Logger, "# Values are space seperated")
-    logData(Logger, "# seconds since epoc, sensor, sensor value")
+    logData(Logger, "# seconds since epoch, sensor, sensor value")
 
     # Write data to their respective logs
     while True:
@@ -218,50 +223,12 @@ def log_data():
         time.sleep(args.wait[0])
 
 
-def display():
-    try:
-        # Create objects
-        cpu = CpuTemp()
-        zone = ZoneTemp()
-        hdd = SmartCtl()
-    except IOError as ioe:
-        if args.verbose:
-            sys.stderr.write("Unable to run: " + str(ioe) + "\n")
-            sys.exit(1)
-        else:
-            sys.exit(1)
-    except Exception as e:
-        if args.verbose:
-            sys.stderr.write("Unable to run: " + str(e) + "\n")
-            sys.exit(1)
-        else:
-            sys.exit(1)
-
-    # Create the logger instance
-    Logger = console_log_setup(logging.INFO)
-    # Create data layout
-    logData(Logger, "# Values are space seperated")
-    logData(Logger, "# seconds since epoc, sensor, sensor value")
-
-    # Write data to their respective logs forever
-    while True:
-        logData(Logger, zone.get_data())
-        logData(Logger, cpu.get_data())
-        logData(Logger, hdd.get_data())
-        if args.once:
-            sys.exit(0)
-        time.sleep(args.wait[0])
-
-
 args = parser.parse_args()
-if args.logfile:
-    try:
+try:
+    if args.logfile:
         log = args.logfile[0]
-        log_data()
-    except (KeyboardInterrupt, SystemExit):
-        sys.exit(0)
-else:
-    try:
-        display()
-    except (KeyboardInterrupt, SystemExit):
-        sys.exit(0)
+    else:
+        log = sys.stdout
+    log_data()
+except (KeyboardInterrupt, SystemExit):
+    sys.exit(0)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/a77d52fbc7e501e11f092d1c341e8b0282552db1...ea39b014d051a39119ac858ceffb2330d6c4c33f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170126/c72bce9d/attachment.html>


More information about the vc mailing list