summaryrefslogtreecommitdiff
path: root/python/skytools/scripting.py
diff options
context:
space:
mode:
authorMarko Kreen2010-08-02 11:44:00 +0000
committerMarko Kreen2010-08-02 11:44:00 +0000
commite4ae2f58907a37bff361e5feaeb193381641fb4e (patch)
treed34df74cde08db908cc5530cd08c9615537b891e /python/skytools/scripting.py
parent9cbd773eb892a8b1a91bca43537affc60417e357 (diff)
Disable use_skylog if non-daemon on console.
This avoids console commands to send errors/warnings to central logging server. Set use_skylog=2 to always enable.
Diffstat (limited to 'python/skytools/scripting.py')
-rw-r--r--python/skytools/scripting.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py
index 2dddfa3c..cf50d42d 100644
--- a/python/skytools/scripting.py
+++ b/python/skytools/scripting.py
@@ -131,13 +131,19 @@ def run_single_process(runnable, daemon, pidfile):
_log_config_done = 0
_log_init_done = {}
-def _init_log(job_name, service_name, cf, log_level):
+def _init_log(job_name, service_name, cf, log_level, is_daemon):
"""Logging setup happens here."""
global _log_init_done, _log_config_done
got_skylog = 0
use_skylog = cf.getint("use_skylog", 0)
+ # if non-daemon, avoid skylog if script is running on console.
+ # set use_skylog=2 to disable.
+ if not is_daemon and use_skylog == 1:
+ if os.isatty(sys.stdout.fileno()):
+ use_skylog = 0
+
# load logging config if needed
if use_skylog and not _log_config_done:
# python logging.config braindamage:
@@ -298,7 +304,11 @@ class DBScript(object):
# per-process name to use in logging
#job_name = %(config_name)s
- # whether centralized logging should be used (loaded from skylog.ini)
+ # whether centralized logging should be used
+ # search-path [ ./skylog.ini, ~/.skylog.ini, /etc/skylog.ini ]
+ # 0 - disabled
+ # 1 - enabled, unless non-daemon on console (os.isatty())
+ # 2 - always enabled
#use_skylog = 0
# default lifetime for database connections (in seconds)
@@ -368,7 +378,7 @@ class DBScript(object):
self.reload()
# init logging
- self.log = _init_log(self.job_name, self.service_name, self.cf, self.log_level)
+ self.log = _init_log(self.job_name, self.service_name, self.cf, self.log_level, self.go_daemon)
# send signal, if needed
if self.options.cmd == "kill":