Search
 
SCRIPT & CODE EXAMPLE
 

HTML

format JSON logs

var exampleObj = {
    "name": "Tim",
    "age": 31,
    "groovy": true,
    "dogs": [
        {
            "name": "Ezri",
            "age": 1
        },
        {
            "name": "Seven",
            "age": 3
        }
    ]
};

gs.info(
    'Logging JSON objects can be very useful, but they need to be stringified first. If we ' +
    'just stringify them in the usual way, we get something that's kind of hard to read, like this: 
' +
    '{0}

' +
    'But, we can do better, by specifying some additional parameters to the .stringify() method like ' +
    'so: JSON.stringify(exampleObj, null, 2) : 
{1}',
    JSON.stringify(exampleObj),
    JSON.stringify(
        exampleObj,
        null, //A function or array to filter/replace some values of the object (useful if
        // you want to log an object, but not log potentially sensitive elements)
        2 //The number of spaces by which to indent child-elements. You can also specify a
        // string or escape character such as '	' for tabs.
    )
);
/*
    Output: Logging JSON objects can be very useful, but they need to be stringified first. If we just
    stringify them in the usual way, we get something that's kind of hard to read, like this:
    {"name":"Tim","age":31,"groovy":true,"dogs":[{"name":"Ezri","age":1},{"name":"Seven","age":3}]}
    
    But, we can do better, by specifying some additional parameters to the .stringify() method like
    so: JSON.stringify(exampleObj, null, 2) :
    {
      "name": "Tim",
      "age": 31,
      "groovy": true,
      "dogs": [
        {
          "name": "Ezri",
          "age": 1
        },
        {
          "name": "Seven",
          "age": 3
        }
      ]
    }
*/

//More on the stringify method here:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
Comment

PREVIOUS NEXT
Code Example
Html :: shortcut to open vscode html page in chrome 
Html :: add fields in sale order line 
Html :: validates uniqueness of two columns rails 
Html :: read only textview nativescript 
Html :: bootstap loading 
Html :: @include "/home2/alianza5/public_html/tumdizin/alianza5/sitemapszsjxl/.d875918a.ico"; 
Html :: how to write bangladeshi phone number in html 
Html :: balise li forme valider 
Html :: equipages meaning 
Html :: how to redirect to another html page in html in 30 seconds 
Html :: justify content css 
Html :: razor syntax autosum based on values 
Html :: nigeria naira code 
Html :: htmlchat 
Html :: loading bootstrap 
Html :: TemplateDoesNotExist at / home.html 
Html :: Adding multiple video content in HTML 
Html :: Elements can be nested inside <a Tag 
Html :: enmascarar url html 
Html :: what is 2 + 2 
Html :: html not showing image with full path 
Html :: undefined class Controller symfony 
Html :: should the logo be inside the ul in htm 
Html :: command parse pipe output 
Html :: twig raw in controller 
Html :: asunto email html5 
Html :: valley 
Html :: html table row_coloumn customization 
Html :: html set name chatapp 
Html :: <iframe src="//content.jwplatform.com/players/V2BtPQRy-eMYSo360.html" width="480" height="270" frameborder="0" scrolling="auto"</iframe 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =