Giter Site home page Giter Site logo

Comments (9)

lulalala avatar lulalala commented on July 24, 2024 4

Since you want ip address, you are lucky that Rails can do it for you. The log_tags option exists in production.rb

config.log_tags = [ :remote_ip ]

from lograge.

pomartel avatar pomartel commented on July 24, 2024 4

I also had to do a lot of digging and finally found the ip address here:
event.payload[:headers][:REMOTE_ADDR]

from lograge.

qbantek avatar qbantek commented on July 24, 2024 4

event.payload[:request].remote_ip seems to be providing the expected results for lograge 0.11.2

from lograge.

danielristic avatar danielristic commented on July 24, 2024 1

As a newcomer to lograge and someone that simply wanted to add IP to logs, I feel this issue is not quite well documented. I've tried the suggested code and I get an empty "ip=" output. The IP is sometimes the only way to match a Rails request with whatever is serving HTTP traffic to the app (Puma, Nginx, ...) so it seems like something pretty useful to have by default.

from lograge.

urbanautomaton avatar urbanautomaton commented on July 24, 2024

You can add extra info to the instrumentation payload without the need for monkeypatching by overriding ActionController::Base#append_info_to_payload in your ApplicationController like so:

class ApplicationController < ActionController::Base
  # ...
  def append_info_to_payload(payload)
    super
    payload[:ip] = request.remote_ip
  end
end

Then you can add it as a custom lograge field in your environment config.

from lograge.

kalleth avatar kalleth commented on July 24, 2024

As extra clarification, to add it as a custom lograge field per @urbanautomaton's previous message you will need this block in config/initializers/.rb:

config.lograge.custom_options = lambda do |event|
  {:ip => event.payload[:ip]}
end

from lograge.

warmwaffles avatar warmwaffles commented on July 24, 2024

Eh not really an elegant solution, but I suppose this will work

from lograge.

warmwaffles avatar warmwaffles commented on July 24, 2024

@lulalala does it output remote_ip=0.0.0.0

from lograge.

benlovell avatar benlovell commented on July 24, 2024

I think this stuff is well documented now so I'll close this issue.

from lograge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.