>
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:
- Solve the problem of attributeerror: module ‘SciPy’ has no attribute ‘Stats’
- [error] attributeerror: module ‘SIP’ has no attribute ‘setapi‘
- AttributeError: module ‘os’ has no attribute ‘mknod’
- Solving attributeerror: module ‘urllib’ has no attribute ‘request’
- AttributeError: module ‘torch’ has no attribute’_six’ [The problem is solved after restart]
- Problem: attributeerror: ‘tensor’ object has no attribute ‘creator’
- AttributeError: module ‘scipy.misc’ has no attribute ‘imread’
- Solving attributeerror: module ‘Matplotlib’ has no attribute ‘artist’
- AttributeError:module“seaborn” has no attribute “lineplot”
- python gensim AttributeError: ‘Doc2Vec‘ object has no attribute ‘dv‘
- AttributeError:module ‘seaborn‘ has no attribute ‘tsplot‘
- Tensorflow error: attributeerror: module ‘tensorflow’ has no attribute ‘unpack’ (‘pack ‘)
- AttributeError: module…ops‘ has no attribute ‘_TensorLike‘, ValueError: `updates` argument..eager
- Tensorflow reported an error when using session module: attributeerror: module ‘tensorflow’ has no attribute ‘session’, which has been solved
- AttributeError: module ‘keras.backend‘ has no attribute ‘eager‘
- AttributeError: module ‘numpy‘ has no attribute ‘getbuffer‘
- AttributeError: module ‘onnxruntime‘ has no attribute ‘InferenceSession‘
- Attributeerror: the solution of module ‘urllib’ has no attribute ‘quote’
- Attributeerror: module “Seaborn” has no attribute “lineplot”
- AttributeError: module ‘cv2.cv2‘ has no attribute ‘face‘