我有一个Python脚本,它接受日志级别并将其设置为默认级别,因此一旦日志消息通过,它将根据级别层次打印或不打印(即如果默认为DEBUG则打印所有消息,如果默认值为ERROR,则仅显示CRITICAL& ERROR消息。
我的Python代码就是这样:
# Sets default log level.
def set_default_level(self,level):
levels = {
'DEBUG': logging.DEBUG,
'INFO': logging.INFO,
'WARNING': logging.WARNING,
'ERROR': logging.ERROR,
'CRITICAL': logging.CRITICAL
}
# Sets up configuration for logging message.
logging.basicConfig(format='%(levelname)s: %(message)s', filename = 'log_file.log', filemode = 'w', level=levels[level])
def log_message(self, lvl, message):
msg_print = {
'[DEBUG]': logging.debug,
'[INFO]': logging.info,
'[WARNING]': logging.warning,
'[ERROR]': logging.error,
'[CRITICAL]': logging.critical
}
msg_print[lvl](message)
此代码在单独运行Python时可以正常工作。但是,当我使用Robot Framework运行此代码时,它不会创建/写入该文件。我目前的框架是这样的:
Test Validate Info Prints
[Documentation] Checks if all BUT debug messages are printed.
... Output should not contain any DEBUG level messages.
Set Default Level ${INFO_LVL}
Log Message ${DEBUG} ${DEBUG_MSG}
Log Message ${INFO} ${INFO_MSG}
Log Message ${ERROR} ${ERROR_MSG}
Log Message ${WARNING} ${WARNING_MSG}
Log Message ${CRITICAL} ${CRITICAL_MSG}
${LogFile}= Get File ./log_file.log
Should contain ${LogFile} this build has no associated authentication!
Should contain ${LogFile} S3 Bucket connected successfully
Should contain ${LogFile} No working Internet connection available
Should contain ${LogFile} Application has failed.
Should not contain ${LogFile} please debug this
这仅测试INFO默认级别。其他测试用例与此非常相似,但所有测试用例在创建文件时都存在同样的问题。我已经调查了这个问题,但没有发现任何有用的东西。我最初使用PowerShell来运行框架,然后我切换到Git BASH和同样的问题。我也在Windows 7上运行。
提前致谢!
答案 0 :(得分:1)
尝试使用您的代码!我开始相信这是预期的行为。
为什么?,因为登录Robot Framework必须使用相同的" Logging"你在代码中使用的python库。
因此,当您实际传递[INFO],[DEBUG]或任何其他消息时,您实际上并没有创建新的记录器,它就像将其传递给Robot Framework的现有记录器一样好!因此,我们在机器人框架的log.html中看到了所有消息。如下:
class Input extends React.Component{
constructor(props){
super(props);
this.state= {
value : this.props.value
}
}
componentWillReceiveProps(nextProps){
this.setState({
value: nextProps.value,
})
}
render(){
return(
<input onChange={this.handleChangeValue.bind(this)} type="text" name={this.props.name} value={this.state.value} placeholder={this.props.placeholder} className={**just class name or send via props too**} />
)
}
handleChangeValue(e){
this.setState({value:e.target.value});
this.props.changeValue(e.target.value);
}
}
class Login extends React.Component{
constructor(props){
super(props);
this.state= {
emailValue : '',
passwordValue: '',
...
}
}
render(){
return(
<Input type="text" name='email' value={this.state.emailValue} placeholder={'Write email'} className='someName' changeValue={this.changeEmailValue.bind(this)} />
<Input type="text" name='password' value={this.state.passwordValue} placeholder={'Write password'} className='someName' changeValue={this.changePasswordValue.bind(this)} />
)
}
changeEmailValue(value){
this.setState({emailValue:value});
}
changePasswordValue(value){
this.setState({passwordValue:value});
}
}
这只是一个想法!