Log4J动态配置(Log4J dynamic configuration)
有没有办法动态配置log4j记录器。 我希望每个类的实例都写入一个不同的文件(基于一些在实例之间唯一的属性)。 我想配置除XML配置文件以外的所有内容,然后为每个实例配置文件。
有没有办法用log4j做到这一点?
Is there any way to configure log4j loggers dynamically. I want each instance of a class to write to a different file (base on say some property that is unique between instances). I would like to configure everything except the file from XML configuration and then for each instance to set the file.
Is there any way to do this using log4j?
原文:https://stackoverflow.com/questions/6998323
最满意答案
不幸的是没有找到答案所以做了以下解决方法:
@genre_ids = project_params[:genres_projects_attributes][:genre_id] @genre_ids.each do |g| GenresProject.create!(project_id: @project.id, genre_id: g) end
更新:
我发现这是导致问题的第一个空白值。 从Rails 4.x开始,您还可以在表单中添加
include_hidden: false
。再次更新:
if project_params[:genres_projects_attributes] @project.genres.delete_all project_params[:genres_projects_attributes][:genre_id].each do |g| @project.genres << Genre.find(g) end @project.update!(project_params.except :genres_projects_attributes) else @project.update!(project_params)
Unfortunately didn't find an answer so did the following workaround:
@genre_ids = project_params[:genres_projects_attributes][:genre_id] @genre_ids.each do |g| GenresProject.create!(project_id: @project.id, genre_id: g) end
UPDATE:
I found out that it was the first blank value that was causing the issue. As of Rails 4.x, you can also add
include_hidden: false
in your form.UPDATE AGAIN:
if project_params[:genres_projects_attributes] @project.genres.delete_all project_params[:genres_projects_attributes][:genre_id].each do |g| @project.genres << Genre.find(g) end @project.update!(project_params.except :genres_projects_attributes) else @project.update!(project_params)
相关问答
更多-
没有将Array隐式转换为Integer(TypeError)(No implicit conversion of Array into Integer (TypeError))[2022-04-14]
方法each_with_index将第二个参数映射为索引。 改为使用它: arr.each_with_index.select {|element, i| arr[i] == "a"} 实现目标的更好方法: def near_ab(string) arr = string.split("") a_position = arr.index('a') # Array#index returns the index of the first element that match `'a'` in thi ... -
第二个参数是哈希,而不是字符串。 如果您希望您的字符串成为标签: <%= f.input :type, { label: 'What of equipment or materials are you seeking' } %> http://rubydoc.info/github/plataformatec/simple_form/master/SimpleForm/FormBuilder#input-instance_method The second argument is a hash, not ...
-
TypeError:关联时没有将String隐式转换为Integer(TypeError: no implicit conversion of String into Integer on association)[2022-03-24]
您正在使用has_many :products, through: :order_products .so而不是尝试Order.includes(:products).first 首先获得订单的产品 ,您可以使用: - ##to get all products using order Order.first.products ##to get all order using products Product.first.orders 因为您已经为此目的使用了公共连接表order_products ,所以 ... -
关于为什么OP在他的本地版本和Heroku上看到不同行为的基本答案是因为他对他正在使用的一个宝石进行了修改,并且这些修改在部署时没有被推动。 解决方案是直接在您的Rails应用程序中嵌入gem的源代码, 如此问题 ,或者在Github上分叉gem并引用Gemfile中的Gemfile 。 听起来他选择了前者,现在他的本地版本和Heroku之间有着一致的行为。 The basic answer as to why OP was seeing different behavior on his local bu ...
-
看起来这个页面的很大一部分是用javascript构建的。 如果你看一下你得到的原始html,你将看不到你正在寻找的内容,因为你实际上是在卷曲来获取数据。 你应该怎么办? 我会说你有两个选择: 获取所需数据的最简单方法是获取他们在#pdp-model-data使用的json 使用某种适用于javascript的网络驱动程序。 我尝试了phantomjs,但看起来该页面包含一些无效的语法,它只是拉第一个图像。 例如 require 'capybara/poltergeist' url = "http://w ...
-
Rails 4嵌套表单 - 没有将Symbol隐式转换为Integer(Rails 4 nested form - no implicit conversion of Symbol into Integer)[2022-07-09]
您的fields_for电话应该是公正的 <%= f.fields_for :marflars do |marflars_form| %> <%= marflars_form.text_field :marflar_attr %> <% end %> Rails负责嵌套属性所期望的参数命名约定。 Your fields_for call should be just <%= f.fields_for :marflars do |marflars_form| %> <%= marflars_form ... -
Rails多选表单:没有将String隐式转换为Integer(Rails multiple select form: no implicit conversion of String into Integer)[2023-05-29]
不幸的是没有找到答案所以做了以下解决方法: @genre_ids = project_params[:genres_projects_attributes][:genre_id] @genre_ids.each do |g| GenresProject.create!(project_id: @project.id, genre_id: g) end 更新: 我发现这是导致问题的第一个空白值。 从Rails 4.x开始,您还可以在表单中添加include_hidden: false 。 再次更新: i ... -
没有将Symbol隐式转换为字符串,Paperclip + Rails 4(no implicit conversion of Symbol into String, Paperclip + Rails 4)[2023-08-24]
根据Paperclip文档 ,对于url选项: 此选项的值是字符串,而不是符号。 右 :“:s3_domain_url” 错误 :: s3_domain_url 在您的代码中, url选项被指定为Symbol即:s3_domain_url ,这是不正确的 ,因此导致以下错误 no implicit conversion of Symbol into String url选项值应指定为String即":s3_domain_url" ( 注意引号括起来) 更新paperclip defaults如下: con ... -
RSpec - 类型错误 - 没有将String隐式转换为Integer(RSpec - Type error - no implicit conversion of String into Integer)[2022-04-07]
正如评论中所提到的,问题是JSON对象返回一个对象数组。 所以适当的测试期望如下: expect(json.first["name"]).to eq("Good Coffee Co.") expect(json.first["description"]).to eq("Hipster Good") expect(json.first["image_url"]).to eq("http://www.example.com/foo_bar.jpg") expect(json.first["city"]).to ... -
试试这个 = select_tag :ethnicity, options_for_select(['Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other']) 请注意options_for_select方法 资源 Try this = select_tag :ethnicity, options_fo ...