Skip to content

Commit

Permalink
fix logger initialization
Browse files Browse the repository at this point in the history
The global LOG should be initialized only after the setup_logger
call which reads up the log config.

If the LOG is initialized at module import time it will use the
default Python logging config. By default this will print the
messages to the standard output which might not be a problem.

Some log messages might go to the wrong place (stdout) before the
logging config is read up in setup_logger if the default setting
in the log config forwards the log messages not to the stdout.
  • Loading branch information
Gyorgy Orban committed Jan 24, 2018
1 parent b1f7480 commit 52d640a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
26 changes: 18 additions & 8 deletions libcodechecker/cmd/cmd_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@
from libcodechecker.util import split_server_url


LOG = logger.get_logger('system')
# Needs to be set in the handler functions.
LOG = None


def init_logger(level, logger_name='system'):
logger.setup_logger(level)
global LOG
LOG = logger.get_logger(logger_name)


class CmdLineOutputEncoder(json.JSONEncoder):
Expand Down Expand Up @@ -105,7 +112,8 @@ def add_filter_conditions(report_filter, filter_str):


def handle_list_runs(args):
logger.setup_logger(args.verbose)

init_logger(args.verbose)

client = setup_client(args.product_url)
runs = client.getRunData(None)
Expand All @@ -126,7 +134,8 @@ def handle_list_runs(args):


def handle_list_results(args):
logger.setup_logger(args.verbose)

init_logger(args.verbose)

client = setup_client(args.product_url)

Expand Down Expand Up @@ -178,7 +187,7 @@ def handle_list_results(args):

def handle_diff_results(args):

logger.setup_logger(args.verbose)
init_logger(args.verbose)

context = generic_package_context.get_context()

Expand Down Expand Up @@ -573,7 +582,8 @@ def print_reports(client, reports, output_format):


def handle_list_result_types(args):
logger.setup_logger(args.verbose)

init_logger(args.verbose)

def get_statistics(client, run_ids, field, values):
report_filter = ttypes.ReportFilter()
Expand Down Expand Up @@ -681,7 +691,7 @@ def checker_count(checker_dict, key):

def handle_remove_run_results(args):

logger.setup_logger(args.verbose)
init_logger(args.verbose)

client = setup_client(args.product_url)

Expand Down Expand Up @@ -731,7 +741,7 @@ def condition(name, runid, date):

def handle_suppress(args):

logger.setup_logger(args.verbose)
init_logger(args.verbose)

def bug_hash_filter(bug_id, filepath):
filepath = '%' + filepath
Expand Down Expand Up @@ -762,7 +772,7 @@ def bug_hash_filter(bug_id, filepath):

def handle_login(args):

logger.setup_logger(args.verbose)
init_logger(args.verbose)

protocol, host, port = split_server_url(args.server_url)
handle_auth(protocol, host, port, args.username,
Expand Down
17 changes: 13 additions & 4 deletions libcodechecker/cmd/product_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@

from cmd_line_client import CmdLineOutputEncoder

# Needs to be set in the handler functions.
LOG = None

LOG = logger.get_logger('system')

def init_logger(level, logger_name='system'):
logger.setup_logger(level)
global LOG
LOG = logger.get_logger(logger_name)


def handle_list_products(args):
logger.setup_logger(args.verbose)

init_logger(args.verbose)

protocol, host, port = split_server_url(args.server_url)
client = setup_product_client(protocol, host, port)
Expand Down Expand Up @@ -59,7 +66,8 @@ def handle_list_products(args):


def handle_add_product(args):
logger.setup_logger(args.verbose)

init_logger(args.verbose)

protocol, host, port = split_server_url(args.server_url)
client = setup_product_client(protocol, host, port)
Expand Down Expand Up @@ -110,7 +118,8 @@ def handle_add_product(args):


def handle_del_product(args):
logger.setup_logger(args.verbose)

init_logger(args.verbose)

protocol, host, port = split_server_url(args.server_url)
client = setup_product_client(protocol, host, port)
Expand Down

0 comments on commit 52d640a

Please sign in to comment.