Comments (7)
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.
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.
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.
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.
Please re-open this ticket if further action is needed.
from semantic_logger.
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.
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)
- Default formatter doesn't return context by default. HOT 1
- Semantic Logger removes keys from hash passed to loggers
- Support message and payload (v5 feature request) HOT 7
- Cannot use Sentry.init properly with sentry-ruby appender HOT 2
- Add support for New Relic log forwarding feature HOT 9
- Elasticsearch Specifying types in bulk requests is deprecated HOT 4
- Log level signal trap omits :fatal and :error levels HOT 2
- Suggestion: Change Loggable logger initialization from lazy to eager HOT 5
- RSpec test suite hangs intermittently unless `sync!` has been called HOT 1
- SemanticLogger.sync! is Not Thread-Safe
- Semantic Logger + Sidekiq 7 HOT 3
- Exception on `logger.error({ payload: '', foo: 'bar' })` (trying to log an arbitrary hash with `payload` key) HOT 1
- HTTP appender / Possible to write custom Headers HOT 1
- Segmentation fault in Formatters::Base for async appender HOT 2
- Improve CaptureLogEvents test logger HOT 1
- Error is raised when logging first occurs in a signal trap
- Base formatter time_format docs and behavior conflict, with no way to initialize it to nil in the ctor.
- Calling 'reopen' and Adding an Appender Creates 2 Logging Threads HOT 2
- Release Version 4.13 HOT 1
- Intermittent `NameError`/`LoadError` when loading Rails environment HOT 3
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 semantic_logger.