Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sugoi_pretty_json

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sugoi_pretty_json

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

SugoiPrettyJSON

This gem print pretty log for JSON.

Requirements

  • ruby >= 2.1.0

Installation

Add this line to your application's Gemfile:

gem 'sugoi_pretty_json'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sugoi_pretty_json

Usage

require "sugoi_pretty_json"

log = '{"sid":"5a4d","uid":"","dev":"s","messages":["Started GET \"/facilities/show_afte\" for 127.0.0.1 at 2016-08-06 23:59:59 +0900","Processing by FacilitiesController#show_after as */*","  Parameters: {\"q\"=>{\"0\"=>{\"id\"=>\"175\", \"type\"=>\"Facility\", \"css\"=>\"c-btn__favorite p-faci__btn__favorite\"}, \"1\"=>{\"id\"=>\"13452\", \"type\"=>\"Experience\"}, \"2\"=>{\"id\"=>\"6387\", \"type\"=>\"Note\", \"css\"=>\"c-btn__favorite\"}, \"3\"=>{\"id\"=>\"5881\", \"type\"=>\"Note\", \"css\"=>\"c-btn__favorite\"}}}","Completed 200 OK in 20ms (Views: 0.3ms | ActiveRecord: 3.7ms | Solr: 0.0ms)"],"level":"INFO","mt":"GET","pt":"/main","ip":"127.0.0.1","ua":"Mozilla/5.0 (Linux; Android 4.1.2; SO-04E Build/10.1.1.D.2.31) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36","rf":"http://localhost/175"}'

hash = SugoiPrettyJSON.parse(log, only: ['IP Address', 'user_agent', 'params']) do |pretty_json|
  pretty_json.parse_user_agent(json_key: 'ua') do |p|
    p.name   = 'user_agent'
  end
  pretty_json.parse_string(json_key: 'messages') do |p|
    p.name   = 'IP Address'
    p.source = /for (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) at/
  end
  pretty_json.parse_hash(json_key: 'messages') do |p|
    p.name   = 'params'
    p.source = /Parameters: (.*)/m
  end
end

ap hash
# {
#     "user_agent" => "Chrome Mobile 52.0.2743.98",
#         "params" => {
#         "q" => {
#             "0" => {
#                   "id" => "175",
#                 "type" => "Facility",
#                  "css" => "c-btn__favorite p-faci__btn__favorite"
#             },
#             "1" => {
#                   "id" => "13452",
#                 "type" => "Experience"
#             },
#             "2" => {
#                   "id" => "6387",
#                 "type" => "Note",
#                  "css" => "c-btn__favorite"
#             },
#             "3" => {
#                   "id" => "5881",
#                 "type" => "Note",
#                  "css" => "c-btn__favorite"
#             }
#         }
#     },
#     "IP Address" => "127.0.0.1"
# }

FAQs

Package last updated on 03 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc