Git Product home page Git Product logo

Comments (7)

andresbarcenas avatar andresbarcenas commented on June 3, 2024 4

Hello,

I tried setting the log level to :json but I am still getting a partial JSON string including the timestamp, etc:

2020-04-23 00:24:25.366219 I [20657:63966080 logger.rb:41] Rack -- Started -- { :method => "POST", :path => "/sso/ValidateUserSessionWS", :ip => "127.0.0.1" }

unless Rails.env.test? || Rails.env.development?
SemanticLogger.add_appender(
file_name: 'log/staging_json.log',
formatter: :json,
filter: -> log { log.payload.try!(:[], :action) != 'health_check' },
level: :info
)
end

Any ideas?

@reidmorrison Thanks

from semantic_logger.

reidmorrison avatar reidmorrison commented on June 3, 2024

Not sure what you mean by prefix strings? Do you have an example?

The JSON format only adds a new line after each JSON entry so that it can be parsed by standard tools.
For example we use the JSON output file so that Splunk can read it at its leisure.

from semantic_logger.

neumachen avatar neumachen commented on June 3, 2024

The output is like this even if the format is JSON:

Apr 26 12:43:42 boo Semantic Logger[19701]: {"name":"Sidekiq","pid":19701,"thread":"51537380","level":"debug","level_index":1,"host":"foo.foo.foo.com","application":"Semantic Logger","message":"unique_digest : {\"class\"=\u003e\"FooClass\", \"queue\"=\u003e\"default\", \"unique_args\"=\u003e[\"1111111\", \"qq\", \"foo\", {:banks_to_retry=\u003e[22222]}]} into uniquejobs:fa3b01a2aea3bd396d30f39a65285ed0","timestamp":"2017-04-26T17:43:42.636755Z"}

I was expected it to be all JSON.

from semantic_logger.

reidmorrison avatar reidmorrison commented on June 3, 2024

We have this initializer that adds a second log file that is in JSON format so that Splunk can read it:

# Using a json log file with the splunk forwarder to rule out the possibility
# of a splunk outage holding up in flight processes.
unless Rails.env.test? || Rails.env.development?
  SemanticLogger.add_appender(
    file_name: 'log/splunk_json.log',
    formatter: :json,
    filter:    -> log { log.payload.try!(:[], :action) != 'health_check' },
    level:     :info
  )
end

We keep the human readable text file in case we need to debug directly on a server.

Note that we filter out the health check messages so that we don't fill spunk up with noise.

from semantic_logger.

reidmorrison avatar reidmorrison commented on June 3, 2024

Please re-open this ticket if further action is needed.

from semantic_logger.

rutvikpensionwar avatar rutvikpensionwar commented on June 3, 2024

Hi @reidmorrison, my rails app is hosted in AWS as an ECS task and I have configured a Splunk log driver for it. All the ECS logs go to Splunk. I configured the sematic logger to log to STDOUT (like below). However I think Splunk took it as a plain text and and not as JSON. I wasn't able to use Splunk's spath over that log.

config.semantic_logger.add_appender(io: STDOUT,
                                        level: config.log_level,
                                        formatter: :JSON)

However I will try your suggested solution but I have a question - How would Splunk know what log file to consider? Does the file_name in add_appender takes care of it by itself?

from semantic_logger.

reidmorrison avatar reidmorrison commented on June 3, 2024

Yes, the file_name tells the appender where to write the json log file.
Then the Splunk agent needs to be configured to read the from the same path as where you are writing your log file too.

from semantic_logger.

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.