How to use logging_levels method in tox

Best Python code snippet using tox_python

config.py

Source:config.py Github

copy

Full Screen

...3from dtools.enums import LoggingLevel, ConfigAttribute4DTOOLS_DIR = os.path.join(os.path.expanduser("~"), 'dtools')5CONFIG_PATH = os.path.join(DTOOLS_DIR, 'config.json')6REPO_PATH = os.path.dirname(os.path.abspath(__file__))7def _check_logging_levels(logging_levels):8 possible_values = set([e.value for e in LoggingLevel])9 if logging_levels - possible_values:10 raise ValueError(f'Invalid {ConfigAttribute.LOGGING_LEVELS.value} {logging_levels - possible_values}')11def _create_new_config_entry():12 logging_levels = [LoggingLevel.EXCEPTION.value]13 return {14 ConfigAttribute.LOGGING_LEVELS.value: logging_levels,15 ConfigAttribute.LOG_FILE_PATH.value: 'log.txt'16 }17class _Config:18 def __init__(self):19 if not os.path.exists(CONFIG_PATH):20 self._create_new_config_json()21 else:22 with open(CONFIG_PATH, 'r') as f:23 self._config_json = json.load(f)24 if REPO_PATH not in self._config_json:25 self.add_repo_to_config()26 else:27 _check_logging_levels(self.logging_levels)28 def add_repo_to_config(self):29 self._config_json[REPO_PATH] = _create_new_config_entry()30 self.save()31 def _create_new_config_json(self):32 self._config_json = {33 REPO_PATH: _create_new_config_entry()34 }35 self.save()36 def save(self):37 with open(CONFIG_PATH, 'w') as f:38 json.dump(self._config_json, f, indent=4)39 def set_logging_levels(self, logging_levels):40 logging_levels = set(logging_levels)41 _check_logging_levels(logging_levels)42 self._config_json[REPO_PATH][ConfigAttribute.LOGGING_LEVELS.value] = list(logging_levels)43 self.save()44 @property45 def logging_levels(self):46 return set(self._config_json[REPO_PATH][ConfigAttribute.LOGGING_LEVELS.value])47 @property48 def log_file_path(self):49 return self._config_json[REPO_PATH][ConfigAttribute.LOG_FILE_PATH.value]...

Full Screen

Full Screen

lambda_handler.py

Source:lambda_handler.py Github

copy

Full Screen

1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4"""5import json6import logging7import os8import traceback9import line_handler10logger = logging.getLogger(__name__)11def lambda_handler(event, context):12 _lambda_logging_init()13 headers = event["headers"] # or event["multiValueHeaders"]14 # prm1 = event["pathParameters"]["prm1"]15 # prm2 = event["queryStringParameters"]["prm2"]16 body = event["body"]17 logger.info(headers)18 try:19 result = line_handler.callback(headers, body)20 return {"statusCode": 200, "body": json.dumps(result)}21 except Exception as e:22 result = {"result": "failed", "message": traceback.format_exc()}23 logger.info(json.dumps(result), exc_info=e)24 return {"statusCode": 500, "body": json.dumps(result)}25def _lambda_logging_init():26 """27 logging の初期化。LOGGING_LEVEL, LOGGING_LEVELS 環境変数を見て、ログレベルを設定する。28 LOGGING_LEVELS - "module1=DEBUG,module2=INFO" という形の文字列を想定。自分のモジュールのみ DEBUG にするときなどに利用29 """30 logging.getLogger().setLevel(os.getenv('LOGGING_LEVEL', 'INFO')) # lambda の場合はロガー設定済みのためこちらが必要31 if os.getenv('LOGGING_LEVELS'):32 for mod_lvl in os.getenv('LOGGING_LEVELS').split(','):33 mod, lvl = mod_lvl.split('=')...

Full Screen

Full Screen

pylogger.py

Source:pylogger.py Github

copy

Full Screen

1import logging2from pytorch_lightning.utilities import rank_zero_only3def get_pylogger(name=__name__) -> logging.Logger:4 """Initializes multi-GPU-friendly python command line logger."""5 logger = logging.getLogger(name)6 # this ensures all logging levels get marked with the rank zero decorator7 # otherwise logs would get multiplied for each GPU process in multi-GPU setup8 logging_levels = ("debug", "info", "warning", "error", "exception", "fatal", "critical")9 for level in logging_levels:10 setattr(logger, level, rank_zero_only(getattr(logger, level)))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful