python logging:logger不会写入文件

时间:2018-02-07 10:13:01

标签: python logging

我正在开发一个包含多个模块的项目,这些模块都应该记录到同一个文件中。

初始化记录器:

parentLogger = logging.getLogger('PARENTLOGGER')
logger = logging.getLogger('PARENTLOGGER.' + __name__)
#set format
fmt = logging.Formatter('%(asctime)s [%(levelname)s] %(name)s: %(message)s')
#set handler for command line
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(fmt)
#set file handler
open('data/logs.log', 'w+').close() #for creating the file in case it doesnt exists. I got exceptions otherwise.
fh = RotatingFileHandler('data/logs.log', maxBytes=5242880, backupCount=1)
fh.setLevel(logging.DEBUG)
fh.setFormatter(fmt)
parentLogger.addHandler(fh)
parentLogger.addHandler(ch)
#

,在所有其他模块上,我打电话:

self._logger = logging.getLogger('PARENTLOGGER.' + __name__)

问题是旋转文件处理程序不会向日志文件写入任何内容。在任何模块中。

我是否正确配置了记录器?我从蟒蛇的伐木食谱中尝试了几个例子没有成功......

提前致意并表示感谢!

1 个答案:

答案 0 :(得分:0)

您应该告诉Yii::import('application.extensions.phpmailer.JPhpMailer'); $mail = new JPhpMailer; $mail->IsSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->Port = 25; $mail->SMTPKeepAlive = true; $mail->SMTPAuth = true; $mail->Mailer = "smtp"; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = '*****@gmail.com';// $user->email $mail->Password = '********';// $user->pass $mail->SetFrom('******@gmail.com', '********'); $mail->Subject = 'Inviting you '; $mail->MsgHTML($user->contactName.' '.$user->email.' '.$user->phone.' has signed Up & This is your password ' .$password); $mail->AddAddress($user->email, $user->contactName); $mail_send_flag=$mail->Send(); 何时以及要记录什么。此外,默认情况下将创建日志文件,无需自行创建。这是一个简单的例子:

logging