Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ロギング

 ロギング

I gave this lightning talk at React Native Meetup #22.

Avatar for Jamie Birch

Jamie Birch

June 25, 2025
Tweet

More Decks by Jamie Birch

Other Decks in Technology

Transcript

  1. const result = hoge(); // ᶃ ίϯιʔϧ console.log(result); // ᶄ

    όοΫΤϯυ fetch('https://ore-no-backend.jp', { method: 'POST', body: `${result}`, }); 192.168.1.1 - - 200 POST / [object Object] (NOBRIDGE) LOG {"1": {"2": {"3": [Object]}}}
  2. try { hoge(); } catch (error) { // ᶃ ίϯιʔϧ

    console.error(error); // ᶄ όοΫΤϯυ fetch('https://ore-no-backend.jp', { method: 'POST', body: `${error}`, }); } 192.168.1.1 - - 200 POST / Error hoge (NOBRIDGE) ERROR [Error: hoge]
  3. Error: hoge at file:///Users/shirakaba/demo.js:4:23 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__

    (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) { [cause]: Error: fuga at file:///Users/shirakaba/demo.js:4:51 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) } ཧ૝ͳΞ΢τϓοτ ᶃ ελοΫτϨʔε ᶄ ݪҼ
  4. JSON.stringify() ͷऑ఺ console.log(JSON.stringify(error)); (NOBRIDGE) LOG {} const hoge = {

    fuga: {} }; hoge.fuga = hoge; console.log(JSON.stringify(hoge)); (NOBRIDGE) ERROR [TypeError: cyclical structure in JSON object]
  5. util.inspect() Λ঺հ͠Α͏ • import { inspect } from 'node:util'; ͸

    Node.js ͷίΞϞδϡʔϧɻ • σʔλܕΛέʔεόΠέʔεͰจࣈྻʹγϦΞϥΠζ͢ΔͨΊͷ΋ͷɻ • ԿͰ΋ରԠͰ͖Δʂ • React Native Ͱ΋࢖͑Δͱ͍͍ͳ…
  6. import { inspect } from "util-inspect-isomorphic"; // ⭐ error.causeΛγϦΞϥΠζ͢Δ ⭐

    console.error(inspect(new Error("hoge", { cause: new Error("fuga") }))); // Error: hoge // at file:///Users/shirakaba/demo.js:4:23 // at ModuleJob.run (node:internal/modules/esm/module_job:274:25) // at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) // at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) { // [cause]: Error: fuga // at file:///Users/shirakaba/demo.js:4:51 // at ModuleJob.run (node:internal/modules/esm/module_job:274:25) // at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) // at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) // } // ⭐ ਂ͘ωετͨ͠ΦϒδΣΫτΛϓϦϯτ͢Δ ⭐ console.log(inspect({ a: { b: { c: { d: {} } } } }, { depth: null })); // { // a: { b: { c: { d: {} } } } // } // ⭐ ΧϥʔΛ෇͚Δ ⭐ console.log(inspect(["hoge", new Date(), true], { colors: true })); // [ 'hoge', 2025-06-07T11:35:11.755Z, true ] // ⭐ φϯόʔʹΞϯμʔείΞΛ෇͚Δ ⭐ console.log(inspect(1000000000, { numericSeparator: true })); // 1_000_000_000