Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/purplecones/log-full
This package will help you to log deeply nested JSON objects.
https://github.com/purplecones/log-full
console json logging output utility
Last synced: about 2 months ago
JSON representation
This package will help you to log deeply nested JSON objects.
- Host: GitHub
- URL: https://github.com/purplecones/log-full
- Owner: purplecones
- Created: 2017-03-23T18:20:35.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-23T19:50:18.000Z (almost 8 years ago)
- Last Synced: 2024-10-19T15:17:46.563Z (3 months ago)
- Topics: console, json, logging, output, utility
- Language: JavaScript
- Homepage:
- Size: 69.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Occasionally I find myself needing to log out deeply nested objects to the console. Sadly, the default logger, `console.log()` does not expand the entire object if it has many levels of depth.
This package will help you to log objects down to any number of levels.
![`log-full` package outputting deeply nested JSON object](log-full-output.png)
# Installation
Add package to your project`yarn add log-full`
Import the package in your code. Preferably at the beginning of your app.
`require('log-full');`
_Note:_ There is no assignment. The package extends console and adds a `console.logFull()` function.
# Usage
```javascript
require('log-full');const deepObject = {
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Pkwy",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4224764,
"lng" : -122.0842499
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4238253802915,
"lng" : -122.0829009197085
},
"southwest" : {
"lat" : 37.4211274197085,
"lng" : -122.0855988802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"types" : [ "street_address" ]
}
],
"status" : "OK"
};console.log(deepObject);
/*
{ results:
[ { address_components: [Object],
formatted_address: '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA',
geometry: [Object],
place_id: 'ChIJ2eUgeAK6j4ARbn5u_wAGqWA',
types: [Object] } ],
status: 'OK' }
*/console.logFull(deepObject);
/*
{ results:
[ { address_components:
[ { long_name: '1600',
short_name: '1600',
types: [ 'street_number' ] },
{ long_name: 'Amphitheatre Pkwy',
short_name: 'Amphitheatre Pkwy',
types: [ 'route' ] },
{ long_name: 'Mountain View',
short_name: 'Mountain View',
types: [ 'locality', 'political' ] },
{ long_name: 'Santa Clara County',
short_name: 'Santa Clara County',
types: [ 'administrative_area_level_2', 'political' ] },
{ long_name: 'California',
short_name: 'CA',
types: [ 'administrative_area_level_1', 'political' ] },
{ long_name: 'United States',
short_name: 'US',
types: [ 'country', 'political' ] },
{ long_name: '94043',
short_name: '94043',
types: [ 'postal_code' ] } ],
formatted_address: '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA',
geometry:
{ location: { lat: 37.4224764, lng: -122.0842499 },
location_type: 'ROOFTOP',
viewport:
{ northeast: { lat: 37.4238253802915, lng: -122.0829009197085 },
southwest: { lat: 37.4211274197085, lng: -122.0855988802915 } } },
place_id: 'ChIJ2eUgeAK6j4ARbn5u_wAGqWA',
types: [ 'street_address' ] } ],
status: 'OK' }
*/
```# Options
An option object can be passed as a second parameter. List of available options follow the `util.inspect()` function from https://nodejs.org/api/util.html#util_util_inspect_object_options
```javascript
console.logFull(deepObject, { depth: 3 });
```The default options set by the package are:
```javascript
{
depth: null, // recurse indefinitely
colors: true, // colorize output by types
}
```