Python coloredlogs.install() Examples
The following are 30
code examples of coloredlogs.install().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
coloredlogs
, or try the search function
.
Example #1
Source File: core_library.py From toonapilib with MIT License | 7 votes |
def setup_logging(level): try: import coloredlogs coloredlogs.install(level=level.upper()) except ImportError: LOGGER = logging.getLogger() handler = logging.StreamHandler() handler.setLevel(level.upper()) formatter = logging.Formatter(('%(asctime)s - ' '%(name)s - ' '%(levelname)s - ' '%(message)s')) handler.setFormatter(formatter) LOGGER.addHandler(handler) LOGGER.setLevel(level.upper()) for logger in LOGGERS_TO_DISABLE: logging.getLogger(logger).disabled = True # TODO extend debug logging in the following methods
Example #2
Source File: basset_ios.py From basset-ios with MIT License | 6 votes |
def __init__(self, configuration, merger, extractor, converter): coloredlogs.install() logging.info("Using configuration: \n" + str(configuration)) self.configuration = configuration self.merger = merger self.converter = converter self.extractor = extractor self.merger.source_assets_dir = configuration.generated_assets_dir self.merger.default_xcasset_dir = configuration.xcassets_dir self.converter.input_dir = configuration.raw_assets self.converter.output_dir = configuration.generated_assets_dir self.converter.force_convert = configuration.force_convert self.extractor.input_dir = configuration.extract_path self.extractor.output_dir = configuration.raw_assets
Example #3
Source File: __init__.py From aetros-cli with MIT License | 6 votes |
def apply_config_defaults(config): defaults = { 'model': None, 'dockerfile': None, 'command': None, 'install': None, 'ignore': None, 'image': None, 'server': None, 'parameters': {}, 'import': None, 'root': os.getcwd(), 'working_dir': None, 'servers': None, 'configPath': None, 'before_command': [], } defaults.update(config) return defaults
Example #4
Source File: __init__.py From aetros-cli with MIT License | 6 votes |
def get_logger(name='', debug=None, format=None): import coloredlogs # logging.basicConfig() # this will make paramiko log a lot of stuff logger = logging.getLogger(name if name else 'aetros') level = 'INFO' fmt = '%(message)s' if format is None else format if debug is None: debug = is_debug() if debug: level = 'DEBUG' if format is None: fmt = coloredlogs.DEFAULT_LOG_FORMAT atty = None if '1' == os.getenv('AETROS_ATTY'): atty = True coloredlogs.install(fmt=fmt, level=level, logger=logger, isatty=atty) return logger
Example #5
Source File: log.py From app with MIT License | 6 votes |
def _get_logger(name): logger = logging.getLogger(name) logger.setLevel(logging.DEBUG) # leave the handlers level at NOTSET so the level checking is only handled by the logger logger.addHandler(_get_console_handler()) if ENABLE_CLOUDWATCH: print( "enable cloudwatch, log group", CLOUDWATCH_LOG_GROUP, "; log stream:", CLOUDWATCH_LOG_STREAM, ) logger.addHandler(_get_watchtower_handler()) # no propagation to avoid propagating to root logger logger.propagate = False if COLOR_LOG: coloredlogs.install(level="DEBUG", logger=logger, fmt=_log_format) return logger
Example #6
Source File: detect.py From roca with MIT License | 6 votes |
def try_open_jks(self, data, name): """ Tries to guess JKS password :param name: :param data: :return: """ try: import jks except: logger.warning('Could not import jks, try running: pip install pyjks') raise ImportException('Cannot import pyjks') pwdlist = sorted(list(set(self.jks_file_passwords + self.jks_passwords))) for cur in pwdlist: try: return jks.KeyStore.loads(data, cur) except Exception as e: pass return None
Example #7
Source File: core_library.py From locationsharinglib with MIT License | 6 votes |
def setup_logging(level): try: import coloredlogs coloredlogs.install(level=level.upper()) except ImportError: LOGGER = logging.getLogger() handler = logging.StreamHandler() handler.setLevel(level.upper()) formatter = logging.Formatter(('%(asctime)s - ' '%(name)s - ' '%(levelname)s - ' '%(message)s')) handler.setFormatter(formatter) LOGGER.addHandler(handler) LOGGER.setLevel(level.upper()) for logger in LOGGERS_TO_DISABLE: logging.getLogger(logger).disabled = True # TODO extend debug logging in the following methods
Example #8
Source File: __main__.py From armory with MIT License | 6 votes |
def launch(command_args, prog, description): parser = argparse.ArgumentParser(prog=prog, description=description) _docker_image(parser) _debug(parser) _interactive(parser) _jupyter(parser) _port(parser) _use_gpu(parser) _gpus(parser) args = parser.parse_args(command_args) coloredlogs.install(level=args.log_level) config = {"sysconfig": {"docker_image": args.docker_image}} _set_gpus(config, args.use_gpu, args.gpus) rig = Evaluator(config) rig.run( interactive=args.interactive, jupyter=args.jupyter, host_port=args.port, command="true # No-op", )
Example #9
Source File: test_reckoner.py From reckoner with Apache License 2.0 | 6 votes |
def test_chart_set_values(self): for chart in self.charts: if chart.name == test_flat_values_chart: self.assertEqual(chart.set_values, test_flat_values) self.assertIsInstance(chart.set_values, dict) self.assertIsInstance(chart.set_values['string'], str) self.assertIsInstance(chart.set_values['integer'], int) self.assertIsInstance(chart.set_values['boolean'], bool) elif chart.name == test_nested_values_chart: self.assertEqual(chart.set_values, test_nested_values) elif chart.release_name == test_values_strings_chart: self.assertIsInstance(chart.values_strings['string'], str) self.assertIsInstance(chart.values_strings['integer'], int) self.assertIsInstance(chart.values_strings['boolean'], bool) # FIXME: Related to the FIXME in install() of Chart class.
Example #10
Source File: detect_tls.py From roca with MIT License | 6 votes |
def main(self): """ Main entry point :return: """ parser = self.init_parser() if len(sys.argv) < 2: parser.print_usage() sys.exit(0) self.args = parser.parse_args() self.roca.args.flatten = self.args.flatten self.roca.args.indent = self.args.indent if self.args.debug: coloredlogs.install(level=logging.DEBUG) self.roca.args.debug = True self.work()
Example #11
Source File: logger.py From ACNet with MIT License | 6 votes |
def get_logger(name='', save_dir=None, distributed_rank=0, filename="log.txt"): logger = logging.getLogger(name) coloredlogs.install(level='DEBUG', logger=logger) # logger.setLevel(logging.DEBUG) # don't log results for the non-master process if distributed_rank > 0: return logger formatter = logging.Formatter( "%(asctime)s %(name)s %(levelname)s: %(message)s") # ch = logging.StreamHandler(stream=sys.stdout) # ch.setLevel(logging.DEBUG) # ch.setFormatter(formatter) # logger.addHandler(ch) if save_dir: fh = logging.FileHandler(os.path.join(save_dir, filename)) fh.setLevel(logging.DEBUG) fh.setFormatter(formatter) if len(logger.handlers) > 0: logger.removeHandler(logger.handlers[0]) logger.addHandler(fh) return logger
Example #12
Source File: log.py From ad-versarial with MIT License | 6 votes |
def getlogger(component, level): # create logger logger = getLogger(component) logger.setLevel(level) # create console handler and set level to debug ch = StreamHandler() ch.setLevel(level) # create formatter formatter = Formatter(fmt="[%(asctime)s] %(name)s (%(levelname)s) %(message)s" , datefmt='%d/%b/%Y:%I:%M:%S') # add formatter to ch ch.setFormatter(formatter) # add ch to logger logger.addHandler(ch) coloredlogs.install(level, logger=logger) return logger
Example #13
Source File: log.py From ad-versarial with MIT License | 6 votes |
def getdebuglogger(component): # create logger logger = logging.getLogger(component) logger.setLevel(LEVEL) # create console handler and set level to debug ch = logging.StreamHandler() ch.setLevel(LEVEL) # create formatter formatter = logging.Formatter(fmt="[%(asctime)s] %(name)s (%(levelname)s) %(message)s" , datefmt='%d/%b/%Y:%I:%M:%S') # add formatter to ch ch.setFormatter(formatter) # add ch to logger if not len(logger.handlers): logger.addHandler(ch) coloredlogs.install(LEVEL, logger=logger) return logger
Example #14
Source File: coloredlogs.py From MARA_Framework with GNU Lesser General Public License v3.0 | 6 votes |
def install(level=logging.INFO, **kw): """ Install a :py:class:`ColoredStreamHandler` for the root logger. Calling this function multiple times will never install more than one handler. :param level: The logging level to filter on (defaults to :py:data:`logging.INFO`). :param kw: Optional keyword arguments for :py:class:`ColoredStreamHandler`. """ global root_handler if not root_handler: # Create the root handler. root_handler = ColoredStreamHandler(level=level, **kw) # Install the root handler. root_logger = logging.getLogger() root_logger.setLevel(logging.NOTSET) root_logger.addHandler(root_handler) # TODO Move these functions into ColoredStreamHandler?
Example #15
Source File: core_library.py From towerlib with MIT License | 6 votes |
def setup_logging(level): try: import coloredlogs coloredlogs.install(level=level.upper()) except ImportError: LOGGER = logging.getLogger() handler = logging.StreamHandler() handler.setLevel(level.upper()) formatter = logging.Formatter(('%(asctime)s - ' '%(name)s - ' '%(levelname)s - ' '%(message)s')) handler.setFormatter(formatter) LOGGER.addHandler(handler) LOGGER.setLevel(level.upper()) for logger in LOGGERS_TO_DISABLE: logging.getLogger(logger).disabled = True # TODO extend debug logging in the following methods
Example #16
Source File: logger.py From dynamite-nsm with GNU General Public License v3.0 | 6 votes |
def get_logger(component_name, level=logging.INFO, stdout=True): coloredlogs.DEFAULT_FIELD_STYLES = {'asctime': {'color': 'green'}, 'hostname': {'color': 'magenta'}, 'levelname': {'bold': True, 'color': 'black'}, 'name': {'color': 'cyan', 'bold': True}, 'programname': {'color': 'blue'}, 'username': {'color': 'yellow'}} utilities.makedirs(const.LOG_PATH, exist_ok=True) today_formatted_date = datetime.strftime(datetime.today(), '%d-%m-%Y') logger = logging.getLogger(component_name) logger.setLevel(level) if not len(logger.handlers): fh = logging.FileHandler(os.path.join(const.LOG_PATH, 'dynamite-{}.log'.format(today_formatted_date))) fformatter = logging.Formatter( '%(asctime)s | %(name)15s | %(module)20s | %(funcName)45s | %(lineno)4s | %(levelname)8s | %(message)s') fh.setFormatter(fformatter) logger.addHandler(fh) if stdout: coloredlogs.install(level=level, logger=logger, fmt='%(asctime)s %(name)-15s %(levelname)-10s | %(message)s') logger.propagate = False return logger
Example #17
Source File: epacems_to_parquet.py From pudl with MIT License | 6 votes |
def main(): """Convert zipped EPA CEMS Hourly data to Apache Parquet format.""" # Display logged output from the PUDL package: logger = logging.getLogger(pudl.__name__) log_format = '%(asctime)s [%(levelname)8s] %(name)s:%(lineno)s %(message)s' coloredlogs.install(fmt=log_format, level='INFO', logger=logger) args = parse_command_line(sys.argv) pudl_settings = pudl.workspace.setup.derive_paths( pudl_in=args.pudl_in, pudl_out=args.pudl_out) epacems_to_parquet(datapkg_path=pathlib.Path(args.datapkg), epacems_years=args.years, epacems_states=args.states, out_dir=pathlib.Path( pudl_settings['parquet_dir'], "epacems"), compression=args.compression, partition_cols=('year', 'state'), clobber=args.clobber)
Example #18
Source File: logger.py From Centripetal-SGD with Apache License 2.0 | 6 votes |
def get_logger(name='', save_dir=None, distributed_rank=0, filename="log.txt"): logger = logging.getLogger(name) coloredlogs.install(level='DEBUG', logger=logger) # logger.setLevel(logging.DEBUG) # don't log results for the non-master process if distributed_rank > 0: return logger formatter = logging.Formatter( "%(asctime)s %(name)s %(levelname)s: %(message)s") # ch = logging.StreamHandler(stream=sys.stdout) # ch.setLevel(logging.DEBUG) # ch.setFormatter(formatter) # logger.addHandler(ch) if save_dir: fh = logging.FileHandler(os.path.join(save_dir, filename)) fh.setLevel(logging.DEBUG) fh.setFormatter(formatter) if len(logger.handlers) > 0: logger.removeHandler(logger.handlers[0]) logger.addHandler(fh) return logger
Example #19
Source File: settings.py From GovLens with MIT License | 6 votes |
def setup_logging(): """configure logging call this as soon as possible """ try: import coloredlogs coloredlogs.install(level=logging.INFO) except Exception: logger.warning("Could not import coloredlogs") # fall back to basicConfig logging.basicConfig(level=logging.INFO,) # setup the logger
Example #20
Source File: test_autohelm.py From autohelm with Apache License 2.0 | 5 votes |
def test_tgz_repository(self): self.configure_subprocess_mock('', '', 0) r = Repository(test_repository_dict) self.assertIsInstance(r, Repository) self.assertEqual(r.name, test_repository_dict['name']) self.assertEqual(r.url, test_repository_dict['url']) self.assertEqual(r.install("test_chart"), Response('', '', 0))
Example #21
Source File: setup_cli.py From pudl with MIT License | 5 votes |
def main(): """Set up a new default PUDL workspace.""" # Display logged output from the PUDL package: logger = logging.getLogger(pudl.__name__) log_format = '%(asctime)s [%(levelname)8s] %(name)s:%(lineno)s %(message)s' coloredlogs.install(fmt=log_format, level='INFO', logger=logger) parser = initialize_parser() args = parser.parse_args(sys.argv[1:]) if not args.pudl_in: args.pudl_in = args.pudl_dir if not args.pudl_out: args.pudl_out = args.pudl_dir # Given pudl_in and pudl_out, create a user settings file. pudl_in = pathlib.Path(args.pudl_in).expanduser().resolve() if not pathlib.Path.is_dir(pudl_in): raise FileNotFoundError( f"Directory not found: {pudl_in}") pudl_out = pathlib.Path(args.pudl_out).expanduser().resolve() if not pathlib.Path.is_dir(pudl_out): raise FileNotFoundError( f"Directory not found: {pudl_out}") pudl_defaults_file = pathlib.Path.home() / ".pudl.yml" # Only print out this information and do the defaults setting if that has # been explicitly requested, or there are no defaults already: if not pudl_defaults_file.exists() or args.clobber is True: logger.info(f"Setting default pudl_in: {pudl_in}") logger.info(f"Setting default pudl_out: {pudl_out}") logger.info(f"You can update these default values by editing " f"{pudl_defaults_file}") pudl.workspace.setup.set_defaults(pudl_in, pudl_out, clobber=args.clobber) pudl.workspace.setup.init(pudl_in=pudl_in, pudl_out=pudl_out, clobber=args.clobber)
Example #22
Source File: datastore_cli.py From pudl with MIT License | 5 votes |
def main(): """Manage and update the PUDL datastore.""" # Display logged output from the PUDL package: logger = logging.getLogger(pudl.__name__) log_format = '%(asctime)s [%(levelname)8s] %(name)s:%(lineno)s %(message)s' coloredlogs.install(fmt=log_format, level='INFO', logger=logger) args = parse_command_line(sys.argv) # Generate a list of valid years of data to download for each data source. # If no years were specified, use the full set of valid years. # If years were specified, keep only th years which are valid for that # data source, and optionally output a message saying which years are # being ignored because they aren't valid. years_by_source = {} for source in args.sources: if not args.years: years_by_source[source] = pc.data_years[source] else: years_by_source[source] = [int(year) for year in args.years if int(year) in pc.data_years[source]] if source == "epaipm": years_by_source[source] = pc.data_years[source] continue bad_years = [int(year) for year in args.years if int(year) not in pc.data_years[source]] if args.verbose and bad_years: warnings.warn(f"Invalid {source} years ignored: {bad_years}.") datastore.parallel_update( sources=args.sources, years_by_source=years_by_source, states=args.states, data_dir=str(pathlib.Path(args.datastore_dir, "data")), clobber=args.clobber, unzip=args.unzip, dl=args.download, )
Example #23
Source File: utils.py From rasa_core with Apache License 2.0 | 5 votes |
def configure_colored_logging(loglevel): import coloredlogs field_styles = coloredlogs.DEFAULT_FIELD_STYLES.copy() field_styles['asctime'] = {} level_styles = coloredlogs.DEFAULT_LEVEL_STYLES.copy() level_styles['debug'] = {} coloredlogs.install( level=loglevel, use_chroot=False, fmt='%(asctime)s %(levelname)-8s %(name)s - %(message)s', level_styles=level_styles, field_styles=field_styles)
Example #24
Source File: check-logs.py From clist with Apache License 2.0 | 5 votes |
def __init__(self): self._logger = logging.getLogger('notify.error') coloredlogs.install(logger=self._logger) self._bot = Bot()
Example #25
Source File: log.py From ancient-text-restoration with Apache License 2.0 | 5 votes |
def get(filename, args): logger = logging.getLogger(os.path.basename(filename)) logger.setLevel(getattr(logging, args.loglevel)) coloredlogs.install(level=args.loglevel) logger.addHandler(handler_file) return logger
Example #26
Source File: test_autohelm.py From autohelm with Apache License 2.0 | 5 votes |
def setUpModule(): coloredlogs.install(level="DEBUG") config = Config() config.local_development = True os.makedirs(test_helm_archive) os.environ['HELM_HOME'] = test_files_path # This will eventually be need for integration testing # args = ['helm','init','-c','--home', "{}/.helm".format(test_files_path)] # subprocess.check_output(args)
Example #27
Source File: cli.py From autohelm with Apache License 2.0 | 5 votes |
def cli(ctx, log_level, *args, **kwargs): coloredlogs.install(level=log_level) logging.warn("Autohelm is deprecated. Please use the new package: Reckoner (https://github.com/reactiveops/reckoner)") pass
Example #28
Source File: converter.py From basset-ios with MIT License | 5 votes |
def __init__(self): coloredlogs.install() self.input_dir = "" self.output_dir = "" self.force_convert = False self.converted_files_hashes = {}
Example #29
Source File: test_autohelm.py From autohelm with Apache License 2.0 | 5 votes |
def test_install_succeeds(self, *args): autohelm_instance = autohelm.autohelm.AutoHelm() autohelm_instance.course.plot.return_value = True install_response = autohelm_instance.install() self.assertIsInstance(install_response, bool) self.assertTrue(install_response)
Example #30
Source File: config.py From VLC-Scheduler with MIT License | 5 votes |
def initialize(*args, **kwargs): global config, logger if config is None: config = build_config() if logger is None: try: import coloredlogs except ImportError: coloredlogs = None finally: import logging logger = logging.getLogger(LOGGER_NAME) params = { 'format': '%(asctime)s %(message)s', 'datefmt': '[%H:%M:%S]' } if config.DEBUG: params['level'] = logging.DEBUG else: params['level'] = logging.INFO if coloredlogs: params['fmt'] = params.pop('format') coloredlogs.install(**params) else: logging.basicConfig(**params) # Other loggers if not config.DEBUG: logging.getLogger('schedule').setLevel(logging.WARNING)