未验证 提交 7c7afef7 编写于 作者: K Kaipeng Deng 提交者: GitHub

[cherry-pick] Fix logging to release/1.5 (#18026)

* fix logging unable. test=develop

* unset sys.stdout for stream handler. test=develop

* fix newly add basicConfig. test=develop

* fix import error. test=release/1.5
上级 6e3c9dd7
...@@ -19,6 +19,7 @@ from .... import io ...@@ -19,6 +19,7 @@ from .... import io
from .... import profiler from .... import profiler
from .... import scope_guard from .... import scope_guard
from ....data_feeder import DataFeeder from ....data_feeder import DataFeeder
from ....log_helper import get_logger
from ..graph import * from ..graph import *
from .config import ConfigFactory from .config import ConfigFactory
import numpy as np import numpy as np
...@@ -33,9 +34,8 @@ import traceback ...@@ -33,9 +34,8 @@ import traceback
__all__ = ['Context', 'Compressor'] __all__ = ['Context', 'Compressor']
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
def cached_reader(reader, sampled_rate, cache_path, cached_id): def cached_reader(reader, sampled_rate, cache_path, cached_id):
......
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
from ..core.strategy import Strategy from ..core.strategy import Strategy
from ....framework import Program, Variable, program_guard from ....framework import Program, Variable, program_guard
from ....log_helper import get_logger
from .... import Executor from .... import Executor
import logging import logging
__all__ = ['DistillationStrategy'] __all__ = ['DistillationStrategy']
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
class DistillationStrategy(Strategy): class DistillationStrategy(Strategy):
......
...@@ -15,13 +15,14 @@ ...@@ -15,13 +15,14 @@
import logging import logging
import socket import socket
from threading import Thread from threading import Thread
from ....log_helper import get_logger
__all__ = ['ControllerServer'] __all__ = ['ControllerServer']
logging.basicConfig( _logger = get_logger(
format='ControllerServer-%(asctime)s-%(levelname)s: %(message)s') __name__,
_logger = logging.getLogger(__name__) logging.INFO,
_logger.setLevel(logging.INFO) fmt='ControllerServer-%(asctime)s-%(levelname)s: %(message)s')
class ControllerServer(object): class ControllerServer(object):
......
...@@ -16,6 +16,7 @@ from ..graph import GraphWrapper ...@@ -16,6 +16,7 @@ from ..graph import GraphWrapper
from .controller_server import ControllerServer from .controller_server import ControllerServer
from .search_agent import SearchAgent from .search_agent import SearchAgent
from ....executor import Executor from ....executor import Executor
from ....log_helper import get_logger
import re import re
import logging import logging
import functools import functools
...@@ -24,10 +25,10 @@ from .lock import lock, unlock ...@@ -24,10 +25,10 @@ from .lock import lock, unlock
__all__ = ['LightNASStrategy'] __all__ = ['LightNASStrategy']
logging.basicConfig( _logger = get_logger(
format='LightNASStrategy-%(asctime)s-%(levelname)s: %(message)s') __name__,
_logger = logging.getLogger(__name__) logging.INFO,
_logger.setLevel(logging.INFO) fmt='LightNASStrategy-%(asctime)s-%(levelname)s: %(message)s')
class LightNASStrategy(Strategy): class LightNASStrategy(Strategy):
......
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
import logging import logging
import socket import socket
from ....log_helper import get_logger
__all__ = ['SearchAgent'] __all__ = ['SearchAgent']
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
class SearchAgent(object): class SearchAgent(object):
......
...@@ -17,12 +17,12 @@ import re ...@@ -17,12 +17,12 @@ import re
import logging import logging
import functools import functools
import copy import copy
from ....log_helper import get_logger
__all__ = ['AutoPruneStrategy'] __all__ = ['AutoPruneStrategy']
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
class AutoPruneStrategy(PruneStrategy): class AutoPruneStrategy(PruneStrategy):
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
from ..core.strategy import Strategy from ..core.strategy import Strategy
from ..graph import VarWrapper, OpWrapper, GraphWrapper from ..graph import VarWrapper, OpWrapper, GraphWrapper
from ....framework import Program, program_guard, Parameter from ....framework import Program, program_guard, Parameter
from ....log_helper import get_logger
from .... import layers from .... import layers
import prettytable as pt import prettytable as pt
import numpy as np import numpy as np
...@@ -28,9 +29,8 @@ import sys ...@@ -28,9 +29,8 @@ import sys
__all__ = ['SensitivePruneStrategy', 'UniformPruneStrategy', 'PruneStrategy'] __all__ = ['SensitivePruneStrategy', 'UniformPruneStrategy', 'PruneStrategy']
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
class PruneStrategy(Strategy): class PruneStrategy(Strategy):
......
...@@ -18,12 +18,12 @@ import six ...@@ -18,12 +18,12 @@ import six
import numpy as np import numpy as np
from .... import core from .... import core
from ..core.strategy import Strategy from ..core.strategy import Strategy
from ....log_helper import get_logger
__all__ = ['MKLDNNPostTrainingQuantStrategy'] __all__ = ['MKLDNNPostTrainingQuantStrategy']
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
class MKLDNNPostTrainingQuantStrategy(Strategy): class MKLDNNPostTrainingQuantStrategy(Strategy):
......
...@@ -21,14 +21,14 @@ from .... import core ...@@ -21,14 +21,14 @@ from .... import core
from ....compiler import CompiledProgram from ....compiler import CompiledProgram
from ....compiler import BuildStrategy from ....compiler import BuildStrategy
from ....framework import IrGraph, Variable, Program from ....framework import IrGraph, Variable, Program
from ....log_helper import get_logger
from ..core.strategy import Strategy from ..core.strategy import Strategy
from .quantization_pass import * from .quantization_pass import *
__all__ = ['QuantizationStrategy'] __all__ = ['QuantizationStrategy']
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
class QuantizationStrategy(Strategy): class QuantizationStrategy(Strategy):
......
...@@ -17,12 +17,12 @@ import numpy as np ...@@ -17,12 +17,12 @@ import numpy as np
import copy import copy
import math import math
import logging import logging
from ....log_helper import get_logger
__all__ = ['EvolutionaryController', 'SAController'] __all__ = ['EvolutionaryController', 'SAController']
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
class EvolutionaryController(object): class EvolutionaryController(object):
......
...@@ -24,10 +24,10 @@ import numpy as np ...@@ -24,10 +24,10 @@ import numpy as np
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid.contrib.slim.core import Compressor from paddle.fluid.contrib.slim.core import Compressor
from paddle.fluid.log_helper import get_logger
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
def parse_args(): def parse_args():
......
...@@ -24,12 +24,12 @@ import copy ...@@ -24,12 +24,12 @@ import copy
import errno import errno
import logging import logging
from paddle.fluid.log_helper import get_logger
__all__ = ["HDFSClient", "multi_download", "multi_upload"] __all__ = ["HDFSClient", "multi_download", "multi_upload"]
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s') _logger = get_logger(
_logger = logging.getLogger("hdfs_utils") __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
class HDFSClient(object): class HDFSClient(object):
......
...@@ -22,15 +22,17 @@ import paddle ...@@ -22,15 +22,17 @@ import paddle
from paddle.fluid import core from paddle.fluid import core
from paddle.fluid import io from paddle.fluid import io
from paddle.fluid import Program from paddle.fluid import Program
from paddle.fluid.log_helper import get_logger
__all__ = [ __all__ = [
"load_persistables_for_increment", "load_persistables_for_inference", "load_persistables_for_increment", "load_persistables_for_inference",
"convert_dist_to_sparse_program" "convert_dist_to_sparse_program"
] ]
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s') _logger = get_logger(
_logger = logging.getLogger("lookup_table_utils") 'lookup_table_utils',
_logger.setLevel(logging.INFO) logging.INFO,
fmt='%(asctime)s-%(levelname)s: %(message)s')
model_filename = "__model__" model_filename = "__model__"
lookup_table_dir = "__lookup_table__" lookup_table_dir = "__lookup_table__"
......
...@@ -20,10 +20,10 @@ import os ...@@ -20,10 +20,10 @@ import os
import paddle import paddle
import paddle.fluid.incubate.data_generator as data_generator import paddle.fluid.incubate.data_generator as data_generator
from paddle.fluid.log_helper import get_logger
logging.basicConfig() logger = get_logger(
logger = logging.getLogger("paddle") "paddle", logging.INFO, fmt='%(asctime)s - %(levelname)s - %(message)s')
logger.setLevel(logging.INFO)
DATA_URL = "http://paddle-ctr-data.bj.bcebos.com/avazu_ctr_data.tgz" DATA_URL = "http://paddle-ctr-data.bj.bcebos.com/avazu_ctr_data.tgz"
DATA_MD5 = "c11df99fbd14e53cd4bfa6567344b26e" DATA_MD5 = "c11df99fbd14e53cd4bfa6567344b26e"
......
...@@ -20,12 +20,12 @@ import paddle.fluid as fluid ...@@ -20,12 +20,12 @@ import paddle.fluid as fluid
import paddle.fluid.incubate.fleet.base.role_maker as role_maker import paddle.fluid.incubate.fleet.base.role_maker as role_maker
from paddle.fluid.incubate.fleet.parameter_server.distributed_transpiler import fleet from paddle.fluid.incubate.fleet.parameter_server.distributed_transpiler import fleet
from paddle.fluid.transpiler.distribute_transpiler import DistributeTranspilerConfig from paddle.fluid.transpiler.distribute_transpiler import DistributeTranspilerConfig
from paddle.fluid.log_helper import get_logger
import ctr_dataset_reader import ctr_dataset_reader
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s') logger = get_logger(
logger = logging.getLogger("fluid") "fluid", logging.INFO, fmt='%(asctime)s - %(levelname)s - %(message)s')
logger.setLevel(logging.INFO)
def parse_args(): def parse_args():
......
...@@ -25,6 +25,7 @@ from paddle.fluid import layers ...@@ -25,6 +25,7 @@ from paddle.fluid import layers
from paddle.fluid.executor import Executor from paddle.fluid.executor import Executor
from paddle.fluid.evaluator import Evaluator from paddle.fluid.evaluator import Evaluator
from paddle.fluid.framework import Program, Parameter, default_main_program, default_startup_program, Variable, program_guard from paddle.fluid.framework import Program, Parameter, default_main_program, default_startup_program, Variable, program_guard
from paddle.fluid.log_helper import get_logger
from . import reader from . import reader
from .reader import * from .reader import *
from . import core from . import core
...@@ -35,9 +36,8 @@ __all__ = [ ...@@ -35,9 +36,8 @@ __all__ = [
'load_persistables', 'save_inference_model', 'load_inference_model' 'load_persistables', 'save_inference_model', 'load_inference_model'
] + reader.__all__ ] + reader.__all__
logging.basicConfig(format='%(asctime)s-%(levelname)s: %(message)s') _logger = get_logger(
_logger = logging.getLogger(__name__) __name__, logging.INFO, fmt='%(asctime)s-%(levelname)s: %(message)s')
_logger.setLevel(logging.INFO)
def is_parameter(var): def is_parameter(var):
......
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import logging
__all__ = ['get_logger']
def get_logger(name, level, fmt=None):
"""
Get logger from logging with given name, level and format without
setting logging basicConfig. For setting basicConfig in paddle
will disable basicConfig setting after import paddle.
Args:
name (str): The logger name.
level (logging.LEVEL): The base level of the logger
fmt (str): Format of logger output
Returns:
logging.Logger: logging logger with given setttings
Examples:
.. code-block:: python
logger = log_helper.get_logger(__name__, logging.INFO,
fmt='%(asctime)s-%(levelname)s: %(message)s')
"""
logger = logging.getLogger(name)
logger.setLevel(level)
handler = logging.StreamHandler()
if fmt:
formatter = logging.Formatter(fmt=fmt)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
...@@ -21,9 +21,9 @@ from collections import defaultdict ...@@ -21,9 +21,9 @@ from collections import defaultdict
import paddle.fluid.core as core import paddle.fluid.core as core
import paddle.fluid.proto.framework_pb2 as framework_pb2 import paddle.fluid.proto.framework_pb2 as framework_pb2
from paddle.fluid.log_helper import get_logger
logger = logging.getLogger(__name__) logger = get_logger(__name__, logging.INFO)
logger.setLevel(logging.INFO)
try: try:
from .graphviz import Graph from .graphviz import Graph
......
...@@ -16,9 +16,9 @@ import logging ...@@ -16,9 +16,9 @@ import logging
import paddle import paddle
import tarfile import tarfile
logging.basicConfig() from paddle.fluid.log_helper import get_logger
logger = logging.getLogger("paddle")
logger.setLevel(logging.INFO) logger = get_logger("paddle", logging.INFO)
DATA_URL = "http://paddle-ctr-data.bj.bcebos.com/avazu_ctr_data.tgz" DATA_URL = "http://paddle-ctr-data.bj.bcebos.com/avazu_ctr_data.tgz"
DATA_MD5 = "c11df99fbd14e53cd4bfa6567344b26e" DATA_MD5 = "c11df99fbd14e53cd4bfa6567344b26e"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册