Comments (15)
Here is my quick and dirty first approach. Works like a charm. Put this in config/initializers
. Note that this is currently LogStash specific.
require 'delayed_job'
class LogstashPlugin < Delayed::Plugin
def self.logstash_logger
@logger ||= create_logger
end
def self.create_logger
return NullLogger.new unless Rails.configuration.logstash.try(:host)
LogStashLogger.new(type: Rails.configuration.logstash.try(:type),
host: Rails.configuration.logstash.try(:host),
port: Rails.configuration.logstash.try(:port))
end
class NullLogger
def info(*args)
end
end
callbacks do |lifecycle|
lifecycle.around(:invoke_job) do |job, *args, &block|
start = Time.now
block.call(job, *args)
runtime = Time.now - start
queued = start - job.created_at if job.created_at
logstash_logger.info(
event: 'delayed_job_completed',
id: job.id,
priority: job.priority,
queue: job.queue,
runtime: runtime,
name: job.name,
created_at: job.created_at,
started_at: start,
queued: queued)
end
end
end
Delayed::Worker.plugins << LogstashPlugin
from lograge.
Hi @caljess599, thank you for replying. Maybe someone else may find this useful. For me this is a nice blast from the past 😅😁.
from lograge.
@rhomeister Looks like you're using the logstash
formatter? You could write your own formatter to format log messages in the way you want, see https://github.com/roidrage/lograge/blob/master/lib%2Flograge%2Fformatters%2Flogstash.rb for example.
from lograge.
I don't have any deeper knowledge on DelayedJob. How does it work?
Is it using the rails logging system?
from lograge.
It loads the rails environment, so would use the rails logging infrastructure.
from lograge.
In this case it should be possible with a bit of fiddeling making a custom formatter that differentiates (no idea how though) between AR and DJ logs and could split the format them.
from lograge.
Hi guys,
Thanks for your input. As soon as I have some time, I'll see if I can make
a proof of concept.
On 18 February 2015 at 16:00, Andreas Tiefenthaler <[email protected]
wrote:
In this case it should be possible with a bit of fiddeling making a custom
formatter that differentiates (no idea how though) between AR and DJ logs
and could split the format them.—
Reply to this email directly or view it on GitHub
#114 (comment).
from lograge.
👍 Curious what you come up with
from lograge.
We use DJ together with lograge
in our rails apps. Not sure if this is related, but for some reason we have duplicate lines in our logs like
[Worker(host:some_hash pid:some_pid)] Job MyJobName (id=1) COMPLETED after 2
2013-02-11T15:00:00+0000: [Worker(host:some_hash pid:some_pid)] Job MyJobName (id=1) COMPLETED after 3
i.e. one line with a timestamp in front and one without.
from lograge.
@janraasch could you share some code that would allow me to reproduce your setup? You can use a fork of this repo to do so: https://github.com/pxlpnk/lograge-rails-apps
You most likely have to adjust lograge in the Gemfile for your setup.
from lograge.
@pxlpnk thank you for caring. It's a pretty huge app though. The lograge
, rails
and delayed_job
specifics are:
Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '~> 4.0.0'
gem 'lograge', '~> 0.3.1'
gem 'delayed_job_active_record'
gem 'delayed_job_web'
and the application.rb
part is
config.lograge.enabled = true
config.lograge.custom_options = lambda do |event|
params = event.payload[:params].reject do |k|
%w(controller action).include? k
end
{ 'params' => params }
end
Let me know, if that is enough info. If not, I will try to make some time and fork https://github.com/pxlpnk/lograge-rails-apps into a working example.
from lograge.
Thank you, I try to craft a setup with this in the next few days, if I need more I just ping you (:
from lograge.
@pxlpnk did you ever get anywhere with this?
from lograge.
I was playing around with it but didn't get anywhere yet.
from lograge.
@janraasch Not that you still need to know this 5 years later, but the reason you see duplicate lines is because the gem logs everything to STDOUT already, and that output cannot be directed into a logger (at least AFAIK). Therefore, if you specify a logger in your config, e.g., Delayed::Worker.logger = Logger.new(STDOUT)
, you end up doubling the output to STDOUT. (The lines look slightly different because Logger
has a default formatting wrapper.)
from lograge.
Related Issues (20)
- No logs shown in CloudWatch when lograge is enabled (Rails/ECS/Fargate) HOT 1
- Why are we striping params for redirect url?
- [Question] Project status HOT 2
- Monkey patching of Rails::Rack::Logger#call_app loses request.action_dispatch instrumentation HOT 1
- [Question] Logstash-event loaded from gh
- How to add extra log payload in action cable?
- Rails support HOT 1
- Should we demote some of our formatters to "contrib"?
- Unable to Filter ActionCable Params HOT 2
- exception cannot show on rescue_from custom handler exception HOT 1
- custom_payload is "persisted' (or per se kept) between 2 requests HOT 4
- Request: new gem release HOT 5
- Any thoughts on supporting `Turbo::StreamsChannel`? HOT 1
- Sinatra support? HOT 1
- Simpler way to remove all log subscribers. HOT 3
- Redirect in routes not handled by lograge
- Confused about what Rails logging is eliminated HOT 1
- ActionView logs not completely suppressed with Rails 7.1+
- TypeError: no implicit conversion of String into Integer when adding lograge to Rails project with Rack 3.0.9 and Puma 6.4.2 HOT 3
- Suggestion from Rails regarding better patching mechanism
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lograge.