- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经在logging.config文件中配置了日志记录。我创建了一个类,在其中访问此配置文件、启用/禁用记录器并记录一些信息消息。我将此类导入到需要进行日志记录的所有模块中。当我尝试记录到文件时,收到此错误消息。我无法理解这个错误的含义。
File "/usr/local/lib/python3.6/configparser.py", line 959, in getitem raise KeyError(key) KeyError: 'formatters'
logging.config
[loggers]
keys=root
[handlers]
keys=fileHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=INFO
handlers=fileHandler
[handler_fileHandler]
class=FileHandler
level=INFO
formatter=simpleFormatter
args=('example.log','a')
[formatter_simpleFormatter]
class=logging.Formatter
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=
#Log.py
import logging.config
class Monitor(object):
fileName = path.join(path.split(path.dirname(path.abspath(__file__)))[0], "logging.config")
print (fileName) #prints /usr/local/lib/python3.6/site-packages/myproject-0.0.1-py3.6.egg/MyPackageName/logging.config
logging.config.fileConfig(fileName)
logger = logging.getLogger('root')
logger.disabled = False
@staticmethod
def Log(logMessage):
Monitor.logger.info(logMessage)
#sub.py
import Monitor
class Example
def simplelog(self,message):
Monitor.Log("Logging some message here")
#call some function here
Monitor.Log("Logging some other messages here for example")
最佳答案
当我尝试从不在项目根目录上的 python 脚本加载配置时,我遇到了类似的问题。我发现的是:
logging.config.fileConfig
依赖于 configparser并且在使用绝对路径初始化时遇到问题。尝试相对路径。
替换
fileName = path.join(path.split(path.dirname(path.abspath(__file__)))[0], "logging.config")
像这样的东西:
## get path tree from project root and replace children from root with ".."
path_rslv = path.split(path.dirname(path.abspath(__file__)))[1:]
fileName = path.join(*[".." for dotdot in range(len(path_rslv)], "logging.config")
关于python3.6 : KeyError: 'formatters' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47636747/
我向我的记录器添加了两个具有不同格式化程序的处理程序。第一个需要继承 logging.Formatter 来进行自定义格式化。默认格式化程序将满足第二个处理程序的需要。 假设第一个格式化程序只是从消息
我尝试运行一个简单的 .feature 文件以生成 Step 文件所需的代码,但返回以下异常: 下面是pom文件: org.seleniumhq.selenium
userA 在法国,他们将某样东西的价格定为 10 欧元,我获取他们的货币信息,并使用 Locale.current.identifier 将其本地区域的副本记录到数据库,这给出了我 € 并将其保存到
我已经在 android 项目上集成了 checkstyle。但是我收到以下错误: > Unable to create listeners: formatters {[com.puppycrawl.
这个解决方案对我不起作用: Running a spec in RubyMine results in "cannot load such file -- teamcity/spec/runner/f
我正在尝试在 Eclipse 中设置我的第一个 Cucumber。我按照教程视频建议的方式在 Features 文件夹中设置了一个基本功能文件,但尝试作为 cucumber 功能执行时,我得到以下信息
操作系统:Arch Linux,Rails 版本:4,RubyMine:6.3 当我从 Tools - Run Rake Task - spec 运行规范时,我总是会收到此错误: /home/chyl
我正在尝试使用 formattable Awesome 包并获得一个表格,其中包含在多列上缩放的百分比和颜色。 这里是代码 set.seed(123) df % mutate_if(is.nume
我试图将字符串定位在一行上的某个起始位置,无论前一个文本在哪里结束。例如: Mandatory arguments to long options are mandatory for short op
因此,我将以下代码写入文件: Formatter output = ....... // Creating the formatter works, writes to appropriate fil
我知道有很多 HTML 格式化程序。我已经尝试了很多,但没有一个符合我的要求。请建议您是否遇到了可以: 1) 转换 BBCC 进入 BB
在本文中,我们将介绍 Java Formatter.format 方法。 java.util.Formatter 类用作 printf 样式格式字符串的解释器。 Formatter 可以执行布局对齐、
我有一个简单的验证器,可以根据正则表达式检查输入: .directive('test', function () { return { restrict: 'A', require:
假设您有一些表格数据,其中数据长度可能会有所不同,Formatter 类是否有自动调整填充的规定? 所以不是这个(注意 A 列): columnA columnB 1
我有一个这样注释的模型: [DataMember(EmitDefaultValue = false)] [JsonProperty("extension_{0}_name")] public stri
示例数据(修改自 formattable github 文档): df <- data.frame( id = 1:10, name = c("Bob", "Ashley", "James",
我编写了下面的代码,它创建了一个文件并完美地写入它,但我想在输出中查看文件的内容,但我只收到此消息:“java.io.BufferedWriter@140e19d”。我不明白!谁能向我解释一下为什么我
我有兴趣使用 formattable R 包中的工具,但我只想在表格中显示有更改的地方。也就是说,我想要通过 collapse_rows() 函数在 kableExtra 包中提供分层行标签。 例如,
我已经开始使用 Intellij (之前使用过 Eclipse),但我似乎无法模仿 Eclipse 格式 Eclipse Code Formatter 插件完成了大部分工作,但仍然存在一些差异。 例如
我是编码新手,有一个问题如何修复此代码以实际使用用户输入作为创建的文件的新名称。如您所见,我希望在格式化程序中使用字符串“文件名”(例如,输入是“Example.txt”,这应该在格式化程序的构造函数
我是一名优秀的程序员,十分优秀!