Commit 0539c9d7 authored by David Johnson's avatar David Johnson

Separate the log stuff out, and add early-log-via-envvar.

Since the Applicable code logs as it is being used as a decorator as
other files are being parsed, we need a logger before the command-line
options are parsed.  And now, since multiple source files might setup
the root logger, we ensure it only gets hooked up to the console once.
Subsequent calls to configure_logging only affect the logging level.

If you need early debug logging, set ELASTICSLICE_DEBUG to anything.

Oh, and I changed the default log level to WARN, from INFO.
parent d68b82b2
......@@ -101,9 +101,8 @@ import threading
import traceback
import logging
import importlib
from elasticslice.util.util import parse_options, configure_logging, Config
#LOG = logging.getLogger(__name__)
#configure_logging(True)
from elasticslice.util.log import configure_logging
from elasticslice.util.util import parse_options, Config
from elasticslice.util.applicable import Applicable
import elasticslice.rpc.protogeni as pgrpc
import elasticslice.managers.core as coremanagers
......
import logging
import sys
import os
import re
import collections
import inspect
import json as JSON
from elasticslice.util.log import configure_logging
#
# Setup an early logging mode that is necessary for debugging Applicable
# stuff (we haven't parsed args in esclient.py by the time the
# Applicable decorators start running).
#
if os.environ.has_key('ELASTICSLICE_DEBUG'):
configure_logging(debug=True)
else:
configure_logging()
pass
LOG = logging.getLogger(__name__)
DEFAULT_FORMATTER = None
......
import logging
LOGGING_HANDLER = None
def configure_logging(debug=False):
global LOGGING_HANDLER
if LOGGING_HANDLER is None:
formatter = logging.Formatter("%(asctime)s - %(name)-12s - %(levelname)-8s - %(message)s")
console = logging.StreamHandler()
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
LOGGING_HANDLER = console
pass
if debug:
logging.getLogger('').setLevel(logging.DEBUG)
else:
logging.getLogger('').setLevel(logging.WARN)
return
......@@ -149,16 +149,6 @@ def parse_options():
(options, args) = parser.parse_known_args(sys.argv[1:])
return (options, args)
def configure_logging(debug=False):
formatter = logging.Formatter("%(asctime)s - %(name)-12s - %(levelname)-8s - %(message)s")
console = logging.StreamHandler()
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
if debug:
logging.getLogger('').setLevel(logging.DEBUG)
else:
logging.getLogger('').setLevel(logging.INFO)
def is_int(s):
try:
int(s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment