Я использую gem logstasher для преобразования моих журналов в объекты json, затем добавляю строку перед каждой строкой журнала, в разработке все работает нормально.В производстве иногда линии меняются местами.
так и должно быть
{"index":{"_id":"3cc6221b633bd2bd0a95865e9c0c3dfd"}}
{"method":"GET","path":"/public/so_list","format":"*/*","controller":"public","action":"so_list","status":200,"duration":3152.27,"view":246.58,"db":2882.97,"ip":null,"route":null,"request_id":null,"source":"unknown","tags":["request"],"@timestamp":"2018-11-15T18:53:36Z","@version":"1"}
{"index":{"_id":"4b94f72318d88a8d7c1c5e46e5465246"}}
{"method":"GET","path":"/public/ajx_group_items/DY2149","format":"*/*","controller":"public","action":"ajx_group_items","status":200,"duration":118.89,"view":31.89,"db":74.0,"ip":null,"route":null,"request_id":null,"source":"unknown","tags":["request"],"@timestamp":"2018-11-15T18:53:36Z","@version":"1"}
{"index":{"_id":"b1ceb09e59379be7e26bff6b0d91ccd9"}}
{"method":"GET","path":"/public/login","format":"html","controller":"public","action":"login","status":200,"duration":44.24,"view":41.55,"db":1.25,"ip":null,"route":null,"request_id":null,"source":"unknown","tags":["request"],"@timestamp":"2018-11-15T18:53:36Z","@version":"1"}
, а иногда случается, что
строка 2 должна меняться местами со строкой 3
{"index":{"_id":"f6ee3d21d6e424652cdca28e9fdff611"}}
{"index":{"_id":"3c5050daede3f29d0402e888eef02046"}}
{"method":"GET","path":"/public/ajx_group_items/DY7100","format":"*/*","controller":"public","action":"ajx_group_items","status":200,"duration":341.08,"view":169.3,"db":157.56,"ip":null,"route":null,"request_id":null,"source":"unknown","tags":["request"],"@timestamp":"2018-11-15T18:53:37Z","@version":"1"}
{"method":"GET","path":"/public/ajx_group_items/DY7000","format":"*/*","controller":"public","action":"ajx_group_items","status":200,"duration":334.34,"view":191.42,"db":129.59,"ip":null,"route":null,"request_id":null,"source":"unknown","tags":["request"],"@timestamp":"2018-11-15T18:53:37Z","@version":"1"}
{"index":{"_id":"f6f59814f6cd45851d529a4efd1d5989"}}
{"method":"GET","path":"/public/ajx_group_items/DY7210","format":"*/*","controller":"public","action":"ajx_group_items","status":200,"duration":305.02,"view":221.0,"db":72.51,"ip":null,"route":null,"request_id":null,"source":"unknown","tags":["request"],"@timestamp":"2018-11-15T18:53:37Z","@version":"1"}
мой инициализатор выглядит так
if LogStasher.enabled?
LogStasher::ActiveSupport::LogSubscriber.class_eval do
alias :original_process_action :process_action
def process_action(event)
# this creates the first line before each log
log_extra_line = Logger.new("#{Rails.root}/log/logstasher.log")
hash = {index: {_id: event.payload[:request_id]}}
log_extra_line.info(hash.to_json)
# this adds the log line
original_process_action(event)
end
end
end
, тогда я изменил инициализатор на это, предполагая, что если я передаю оба аргумента в функцию, а затем делаю логи, это работает, но у меня все еще естьта же проблема.
if LogStasher.enabled?
LogStasher::ActiveSupport::LogSubscriber.class_eval do
alias :original_process_action :process_action
def process_action(event)
hash = {index: {_id: event.payload[:request_id]}}
do_logs(hash, event)
end
def do_logs(elastic_hash, original_log)
# this creates the first line before each log
log_extra_line = Logger.new("#{Rails.root}/log/logstasher.log")
log_extra_line.info(elastic_hash.to_json)
# this adds the log line
original_process_action(original_log)
end
end
end
Что я делаю не так?