diff options
author | Stan Hu <stanhu@gmail.com> | 2017-09-07 08:41:15 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-09-07 09:09:27 +0300 |
commit | f7c8032e0993a6dc6bb808b0f2234324d3fe9707 (patch) | |
tree | cd74468cc14fc1955feb0faf705e9d78a4e55e97 /lib | |
parent | 21935d85382989e38dd4cc12de55966e0c9b6eba (diff) |
Add JSON logger in `log/api_json.log` for Grape API endpoints
Closes #36189
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/api.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/api_logger.rb | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 1405a5d0f0e..63df22c508b 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -2,6 +2,15 @@ module API class API < Grape::API include APIGuard + LOG_FILENAME = Rails.root.join("log", "api_json.log") + + use GrapeLogging::Middleware::RequestLogger, + logger: ::Gitlab::ApiLogger.new(LOG_FILENAME), + formatter: GrapeLogging::Formatters::Json.new, + include: [ GrapeLogging::Loggers::Response.new, + GrapeLogging::Loggers::FilterParameters.new, + GrapeLogging::Loggers::ClientEnv.new ] + allow_access_with_scope :api prefix :api diff --git a/lib/gitlab/api_logger.rb b/lib/gitlab/api_logger.rb new file mode 100644 index 00000000000..09122b233ea --- /dev/null +++ b/lib/gitlab/api_logger.rb @@ -0,0 +1,8 @@ +module Gitlab + class ApiLogger < ::Logger + + def format_message(severity, timestamp, progname, message) + super + "\n" + end + end +end |