Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate human log format #567

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5c8fe3f
Do not use a global `logger` in test_logging.
htgoebel Aug 22, 2012
baf569e
Fix test-case: logger.set_level() now accepts names (strings), too.
htgoebel Aug 27, 2012
b87bc02
New function `send_result()` to avoid misusing loggers for this.
htgoebel Aug 27, 2012
4c3ec0c
Remove test-cases no longer valid.
htgoebel Aug 28, 2012
5af37be
Fix test-case: private `_level` is no public `level`.
htgoebel Aug 28, 2012
0f78ad6
Adopt test-cases: `logger` will no longer write to stdout.
htgoebel Aug 28, 2012
565e1ab
Fix test-case: remove a duplicate line.
htgoebel Aug 28, 2012
849bddb
Adopt test-cases: log-messages will have level upper-case and less sp…
htgoebel Aug 28, 2012
2ed4a6f
Adopt test-case: local log will get a single time-stamp.
htgoebel Aug 28, 2012
17384bb
Clean: Remove a left-over print statement.
htgoebel Aug 28, 2012
06f4705
Base `shinken.log.Log` on std-Python `logging.Logger`.
htgoebel Aug 28, 2012
e884e74
Use a std TimedRotatingFileHandler for local log.
htgoebel Aug 28, 2012
20b205e
Use a log-handler for sending the Broks.
htgoebel Aug 28, 2012
ac8a29b
Use a Formatter w/ different format if "human format" is selected.
htgoebel Aug 28, 2012
a536b50
Make `Log.set_level()` and alias for std `setLevel()`.
htgoebel Aug 28, 2012
c8d7620
Create main logger using `logging.getLogger()` (adding it to the hier…
htgoebel Aug 28, 2012
2c0ef66
Make console_logger a standard logger using a StreamHandler.
htgoebel Aug 28, 2012
b6a99a9
Take definition of log-levels from std Python logging module.
htgoebel Aug 30, 2012
1d2c1cd
Add test-case for console_logger.
htgoebel Aug 30, 2012
8d780e4
Fix: Need to set format for console_logger.
htgoebel Aug 30, 2012
7d0f045
Clean: Remove unused import and uselessly overwritten method.
htgoebel Aug 30, 2012
4d1edc0
Clean: Remove useless alias `Log.set_level()`, use `setLevel()` instead.
htgoebel Aug 30, 2012
3922ff8
noch zu entfernen von __init__
htgoebel Aug 30, 2012
0e1792f
Clean: Remove useless alias `Log.get_level()`, use `getEffectiveLevel…
htgoebel Aug 30, 2012
51be66e
Clean: Remove `Log.get_level_id()`, use std `getLevelName()` instead.
htgoebel Aug 30, 2012
95c65bf
Add test-suite for `logger.send_result()`.
htgoebel Sep 1, 2012
f643778
Fix typo in comment.
htgoebel Sep 1, 2012
6e63081
Make `logging.send_result` log with level DEBUG and send Brok itself.
htgoebel Sep 1, 2012
08f91f3
Enhance test-case: assert logging level is as expected.
htgoebel Sep 1, 2012
247b4c8
Fix log-level when logging config-errors in business-rules.
htgoebel Sep 1, 2012
176cd46
Enhance test-case: assert logging level is as required to get messages.
htgoebel Sep 1, 2012
bb7a532
Fix: increase log-level for some messages, so their are logged by def…
htgoebel Sep 1, 2012
aaaa711
Fix: Remove usage of `logger.quit()` (which no longer exists).
htgoebel Sep 1, 2012
b531a02
Fix: get_log_match() did not prepare the broks prior to searching.
htgoebel Sep 1, 2012
eaec6d0
Eliminate `human_timestamp_log`.
htgoebel Sep 2, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/shinken-admin
Expand Up @@ -310,9 +310,9 @@ class ShinkenAdmin(cmd.Cmd):
return

daemon = '*' if len(args) < 2 else args[0]
try:
loglevel = logger.get_level_id(args[-1])
except KeyError:
loglevel = shinken.log.getLevelName(args[-1])
if ' ' in loglevel:
# "Level xxx" returned, so this is none of the predefined levels
print "Invalid '%s' log level. Must be one of DEBUG, INFO, WARNING, ERROR, CRITICAL" % args[-1]
return

Expand Down
4 changes: 2 additions & 2 deletions bin/shinken-packs
Expand Up @@ -49,10 +49,10 @@ except ImportError:
imp.load_module('shinken', *imp.find_module('shinken', [os.path.realpath("."), os.path.realpath(".."), os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "..")]))
from shinken.bin import VERSION

from shinken.log import logger
from shinken.log import logger, DEBUG
from shinken.objects.config import Config

logger.set_level(logger.DEBUG)
logger.setLevel(DEBUG)


class Dummy():
Expand Down
11 changes: 0 additions & 11 deletions etc/nagios-windows.cfg
Expand Up @@ -115,17 +115,6 @@ use_ssl=0
#server_cert=etc/certs/server.pem
#hard_ssl_name_check=0


# If in the log you want to see
# [Fri Apr 15 15:43:19 2011] instead of
# [1302874960], put this value to 1
# WARNING:
# But beware, it won't be parsable anymore by tools
# like Centreon or Thruk
human_timestamp_log=0



# The arbiter can have it's own local log
local_log=c:\\shinken\\var\\arbiterd.log

Expand Down
11 changes: 0 additions & 11 deletions etc/nagios.cfg
Expand Up @@ -139,17 +139,6 @@ use_ssl=0
#server_cert=etc/certs/server.pem
#hard_ssl_name_check=0


# If in the log you want to see
# [Fri Apr 15 15:43:19 2011] instead of
# [1302874960], put this value to 1
# WARNING:
# But beware, it won't be parsable anymore by tools
# like Centreon or Thruk
human_timestamp_log=0



# The arbiter can have it's own local log
local_log=arbiterd.log

Expand Down
9 changes: 0 additions & 9 deletions for_fedora/etc/nagios.cfg
Expand Up @@ -112,15 +112,6 @@ use_ssl=0
#server_cert=etc/certs/server.pem
hard_ssl_name_check=0


# If in the log you want to see
# [Fri Apr 15 15:43:19 2011] instead of
# [1302874960], put this value to 1
# WARNING:
# But beware, it won't be parsable anymore by tools
# like Centreon or Thruk
human_timestamp_log=0

# Set to 0 will enable the nagios behavior that will
# launch event handlers even if the element is in downtime.
no_event_handlers_during_downtimes=1
Expand Down
4 changes: 2 additions & 2 deletions libexec/hostd/hostd_packs.py
Expand Up @@ -20,10 +20,10 @@

from shinken.objects.pack import Pack, Packs

from shinken.log import logger
from shinken.log import logger, DEBUG
from shinken.objects.config import Config

logger.set_level(10)
logger.setLevel(DEBUG)


class Dummy():
Expand Down
7 changes: 3 additions & 4 deletions shinken/daemon.py
Expand Up @@ -114,7 +114,7 @@ def have_conf(self):
return self.app.cur_conf is not None

def set_log_level(self, loglevel):
return logger.set_level(loglevel)
return logger.setLevel(loglevel)

# If we are under android, we can't give parameters
if is_android:
Expand Down Expand Up @@ -215,7 +215,6 @@ def do_stop(self):
print('Stopping inter-process message (PYRO)')
if self.pyro_daemon:
pyro.shutdown(self.pyro_daemon)
logger.quit()


def request_stop(self):
Expand Down Expand Up @@ -479,10 +478,10 @@ def do_daemon_init_and_start(self, use_pyro=True):
self.setup_pyro_daemon()

# Setting log level
logger.set_level(self.log_level)
logger.setLevel(self.log_level)
# Force the debug level if the daemon is said to start with such level
if self.debug:
logger.set_level('DEBUG')
logger.setLevel('DEBUG')

# Then start to log all in the local file if asked so
self.register_local_log()
Expand Down
2 changes: 0 additions & 2 deletions shinken/daemons/arbiterdaemon.py
Expand Up @@ -621,8 +621,6 @@ def run(self):
if arb.is_me():
self.me = arb

if self.conf.human_timestamp_log:
logger.set_human_format()
logger.info("Begin to dispatch configurations to satellites")
self.dispatcher = Dispatcher(self.conf, self.me)
self.dispatcher.check_alive()
Expand Down
7 changes: 2 additions & 5 deletions shinken/daemons/hostddaemon.py
Expand Up @@ -47,6 +47,7 @@
import tempfile
import shutil

import shinken
from shinken.objects.config import Config
from shinken.objects.pack import Pack, Packs
from shinken.external_command import ExternalCommandManager
Expand Down Expand Up @@ -366,7 +367,7 @@ def load_config_file(self):
# Ok, here we must check if we go on or not.
# TODO: check OK or not
self.use_local_log = self.conf.use_local_log
self.log_level = logger.get_level_id(self.conf.log_level)
self.log_level = shinken.log.getLevelName(self.conf.log_level)
self.local_log = self.conf.local_log
self.pidfile = os.path.abspath(self.conf.lock_file)
self.idontcareaboutsecurity = self.conf.idontcareaboutsecurity
Expand Down Expand Up @@ -573,10 +574,6 @@ def push_external_commands_to_schedulers(self):

# Main function
def run(self):
if self.conf.human_timestamp_log:
logger.set_human_format()

# Ok start to work :)
self.check_photo_dir()

self.request = request
Expand Down
3 changes: 0 additions & 3 deletions shinken/daemons/schedulerdaemon.py
Expand Up @@ -278,9 +278,6 @@ def setup_new_conf(self):
self.satellites = satellites
#self.pollers = self.app.pollers

if self.conf.human_timestamp_log:
logger.set_human_format()

# Now We create our pollers
for pol_id in satellites['pollers']:
# Must look if we already have it
Expand Down
7 changes: 2 additions & 5 deletions shinken/daemons/skonfdaemon.py
Expand Up @@ -42,6 +42,7 @@
import zipfile
import shutil

import shinken
from shinken.objects.config import Config
from shinken.external_command import ExternalCommandManager
from shinken.dispatcher import Dispatcher
Expand Down Expand Up @@ -331,7 +332,7 @@ def load_config_file(self):
self.community_uri = str(self.conf.community_uri)
self.http_proxy = str(self.conf.http_proxy)
self.use_local_log = self.conf.use_local_log
self.log_level = logger.get_level_id(self.conf.log_level)
self.log_level = shinken.log.getLevelName(self.conf.log_level)
self.local_log = self.conf.local_log
self.pidfile = os.path.abspath(self.conf.lock_file)
self.idontcareaboutsecurity = self.conf.idontcareaboutsecurity
Expand Down Expand Up @@ -535,10 +536,6 @@ def push_external_commands_to_schedulers(self):

# Main function
def run(self):
if self.conf.human_timestamp_log:
logger.set_human_format()

# Ok start to work :)
self.check_photo_dir()

self.request = request
Expand Down
12 changes: 9 additions & 3 deletions shinken/dispatcher.py
Expand Up @@ -396,7 +396,9 @@ def dispatch(self):
logger.warning('[%s] configuration dispatching error for scheduler %s' % (r.get_name(), sched.get_name()))
continue

logger.info('[%s] Dispatch OK of conf in scheduler %s' % (r.get_name(), sched.get_name()))
# Log as `warning` since this is also used
# when a spare gets the config.
logger.warning('[%s] Dispatch OK of conf in scheduler %s' % (r.get_name(), sched.get_name()))

sched.conf = conf
sched.push_flavor = conf.push_flavor
Expand Down Expand Up @@ -512,7 +514,9 @@ def dispatch(self):

if is_sent:
satellite.active = True
logger.info('[%s] Dispatch OK of configuration %s to %s %s' % (r.get_name(), cfg_id, kind, satellite.get_name()))
# Log as `warning` since this is also used
# when a spare gets the config.
logger.warning('[%s] Dispatch OK of configuration %s to %s %s' % (r.get_name(), cfg_id, kind, satellite.get_name()))
# We change the satellite configuration, update our data
satellite.known_conf_managed_push(cfg_id, flavor)

Expand Down Expand Up @@ -546,6 +550,8 @@ def dispatch(self):
if is_sent:
rec.active = True
rec.need_conf = False
logger.info('[%s] Dispatch OK of configuration to receiver %s' % (r.get_name(), rec.get_name()))
# Log as `warning` since this is also used
# when a spare gets the config.
logger.warning('[%s] Dispatch OK of configuration to receiver %s' % (r.get_name(), rec.get_name()))
else:
logger.error('[%s] Dispatching failed for receiver %s' % (r.get_name(), rec.get_name()))
14 changes: 8 additions & 6 deletions shinken/external_command.py
Expand Up @@ -31,7 +31,7 @@
from shinken.contactdowntime import ContactDowntime
from shinken.comment import Comment
from shinken.commandcall import CommandCall
from shinken.log import logger, console_logger
from shinken.log import logger, send_result
from shinken.pollerlink import PollerLink

MODATTR_NONE = 0
Expand Down Expand Up @@ -1286,8 +1286,9 @@ def PROCESS_FILE(self, file_name, delete):
def PROCESS_HOST_CHECK_RESULT(self, host, status_code, plugin_output):
#raise a PASSIVE check only if needed
if self.conf.log_passive_checks:
console_logger.info('PASSIVE HOST CHECK: %s;%d;%s'
% (host.get_name().decode('utf8', 'ignore'), status_code, plugin_output.decode('utf8', 'ignore')))
send_result('PASSIVE HOST CHECK: %s;%d;%s'
% (host.get_name().decode('utf8', 'ignore'),
status_code, plugin_output.decode('utf8', 'ignore')))
now = time.time()
cls = host.__class__
# If globally disable OR locally, do not launch
Expand Down Expand Up @@ -1319,9 +1320,10 @@ def PROCESS_HOST_OUTPUT(self, host, plugin_output):
def PROCESS_SERVICE_CHECK_RESULT(self, service, return_code, plugin_output):
# raise a PASSIVE check only if needed
if self.conf.log_passive_checks:
console_logger.info('PASSIVE SERVICE CHECK: %s;%s;%d;%s'
% (service.host.get_name().decode('utf8', 'ignore'), service.get_name().decode('utf8', 'ignore'),
return_code, plugin_output.decode('utf8', 'ignore')))
send_result('PASSIVE SERVICE CHECK: %s;%s;%d;%s'
% (service.host.get_name().decode('utf8', 'ignore'),
service.get_name().decode('utf8', 'ignore'),
return_code, plugin_output.decode('utf8', 'ignore')))
now = time.time()
cls = service.__class__
# If globally disable OR locally, do not launch
Expand Down