मैं स्क्रीन पर क्यों इस कोड प्रिंट पता नहीं है, लेकिन फाइल करने के लिए नहीं है? फ़ाइल "example1.log" बनाई गई है, लेकिन वहां कुछ भी लिखा नहीं गया है।अजगर basicConfig विधि का उपयोग कर सांत्वना देने लॉग इन करें और फ़ाइल
#!/usr/bin/env python3
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(message)s',
handlers=[logging.FileHandler("example1.log"),
logging.StreamHandler()])
logging.debug('This message should go to the log file and to the console')
logging.info('So should this')
logging.warning('And this, too')
मैं एक प्रवेश वस्तु (example code) बनाने के द्वारा इस समस्या को "नजरअंदाज" है, लेकिन यह मुझे गुस्सा दिलाना रहता है क्यों basicConfig() दृष्टिकोण में विफल रहा है?
पी एस। अगर मैं basicConfig कॉल को बदलने के लिए:
logging.basicConfig(level=logging.DEBUG,
filename="example2.log",
format='%(asctime)s %(message)s',
handlers=[logging.StreamHandler()])
तब सभी लॉग फ़ाइल में हैं और कुछ भी नहीं कंसोल में दिखाई देता
अजगर 2.7 में, केवल कीवर्ड तर्क basicConfig समझता है कि "फ़ाइल नाम", "filemode", "धारा", "प्रारूप", "datefmt" और "स्तर" कर रहे हैं। "हैंडलर" कुछ नहीं करता है। – TocToc