>
import logging
logger = logging.getLogger('mylogger')
logger.setLevel(logging.INFO)
fh=logging.handlers.RotatingFileHandler('/tmp/test.log', mode = 'a', maxBytes=10240, backupCount=3, encoding='utf-8')
formatter = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.info('hello logging')
logger.warning('hello logging')
logger.error('hello logging')
logger.critical('hello logging')
run times error:
AttributeError: ‘module’ object has no attribute ‘handlers’
import logging
import logging.handlers
……
Rerun, the program output normally.
import Logging
import Logging
import Logging
import Logging
import Logging
import Logging
import Logging
import Logging
import Logging
import Logging
import Logging
Therefore, it is necessary to explicitly import the logging.handlers submodule in the access TAB.
but sometimes, when importing some package does not require additional action will automatically import its module, this is because the set of packages for these operations in py files. In other cases, something else you import might also import logging.handlers. Anyway, just make sure that before visiting
The corresponding submodule has already been imported. Sometimes a module that looks like a package is not, such as OS and OS.Path. OS is not a package, it just provides another module called path, which you can access through os.path.
Read More:
- AttributeError: Can‘t get attribute ‘LeNet‘ on <module ‘__ main__ “From (error in torch loading model)
- AttributeError: module ‘os’ has no attribute ‘mknod’
- Python packaged *. Exe is running os.popen (cmd)/ subprocess.Popen *. Exe crashes with invalid [winerror 6] handle
- Solving attributeerror: module ‘urllib’ has no attribute ‘request’
- Attribute
- The problem encountered in pyinstaller packaging “failed to execute script × *”
- In echarts label.formatter Non effectiveness
- ERROR StatusLogger No log4j2 configuration file found.
- Error encountered while executing PIP install: error: complete output from command Python setup.py egg_ info:
- Attributeerror: ‘dataframe’ object has no attribute ‘IX’ error
- AttributeError:module“seaborn” has no attribute “lineplot”
- Error: pg_config executable not found.
- Installation and unloading of Python module
- [SSL: CERTIFICATE_VERIFY_FAILED] Certificate Verify Failed (_ssl.C:579)
- Tensorflow error: module ‘tensorflow’ has no attribute ‘xxx’
- R language error:‘ namespace:lazyeval There is no exit_ The object is eval
- PHP CI (CodeIgniter) log level setting
- SQLServerException: The server failed to resume the transaction. Desc:ab00000002
- Solution to Tomcat starting error listener start
- Failed to commit changes to dconf: the connection is closed