-
Notifications
You must be signed in to change notification settings - Fork 1
log.stringify
Grant Carthew edited this page Oct 25, 2024
·
7 revisions
Type: Function
Parameter: object
Any JavaScript value or object.
Parameter: replacer
A replacer function.
Parameter: spacer
A number or string used to insert space for formatting.
Returns: JSON String
Example:
import Perj from 'perj'
const log = new Perj(options)
const jsonString = log.stringify(process.config)
The log.stringify
function is a convenience method that exposes the internal perj
stringify function. By default this is based on the notation-copy module wrapped by JSON.stringify
.
If you change the stringify function using the stringifyFunction option, then your custom stringify function will be used by the log.stringify
call.
This example shows the use of both the log.stringify
function and the log.write function:
import Perj from 'perj'
const log = new Perj()
const thing = log.stringify(process.config)
log.write(thing)
/*
write function output:
{"target_defaults":{"cflags":[],"default_configuration":"Release","defines":[],"include_dirs":[],"libraries":[]},"variables":{"asan":0,"build_v8_with_gn":false,"coverage":false,"debug_http2":false,"debug_nghttp2":false,"force_dynamic_crt":0,"gas_version":"2.27","host_arch":"x64","icu_data_in":"../../deps/icu-small/source/data/in/icudt61l.dat","icu_endianness":"l","icu_gyp_path":"tools/icu/icu-generic.gyp","icu_locales":"en,root","icu_path":"deps/icu-small","icu_small":true,"icu_ver_major":"61","llvm_version":0,"node_byteorder":"little","node_debug_lib":false,"node_enable_d8":false,"node_enable_v8_vtunejit":false,"node_install_npm":true,"node_module_version":64,"node_no_browser_globals":false,"node_prefix":"/","node_release_urlbase":"https://nodejs.org/download/release/","node_shared":false,"node_shared_cares":false,"node_shared_http_parser":false,"node_shared_libuv":false,"node_shared_nghttp2":false,"node_shared_openssl":false,"node_shared_zlib":false,"node_tag":"","node_target_type":"executable","node_use_bundled_v8":true,"node_use_dtrace":false,"node_use_etw":false,"node_use_openssl":true,"node_use_perfctr":false,"node_use_v8_platform":true,"node_without_node_options":false,"openssl_fips":"","openssl_no_asm":0,"shlib_suffix":"so.64","target_arch":"x64","v8_enable_gdbjit":0,"v8_enable_i18n_support":1,"v8_enable_inspector":1,"v8_no_strict_aliasing":1,"v8_optimized_debug":0,"v8_promise_internal_field_count":1,"v8_random_seed":0,"v8_trace_maps":0,"v8_typed_array_max_size_in_heap":0,"v8_use_snapshot":true,"want_separate_host_toolset":0}}
*/