1. console.clear();
console.log("logging.....");
console.clear();
μ½μμ°½μ μ§μμ€λ€.
2. log level : μλ²μμ λ°μνλ μ¬λ¬ μ΄λ²€νΈμ λν΄μ(μλ¬μ μνμ λ°λΌμ)
console.log("log"); //κ°λ°
console.info("info"); //κ°λ°
console.warn("warn"); //경보
console.error("error"); //μλ¬, μ¬μ©μ μλ¬, μμ€ν
μλ¬
3. assert : 첫λ²μ§Έ μΈμκ° false μΌλλ§ μΆλ ₯
console.assert(2 === 3, "not same!"); //Assertion failed: not same!
console.assert(2 === 2, "same!"); //무μλ΅
4. print object : 보기 μ’κ² μΆλ ₯
const student = { name: "νκΈΈλ", age: 20, company: { name: "AC" } };
console.log(student);
console.table(student); //λ 보기 μ’κ² ν
μ΄λΈ ννλ‘ μΆλ ₯ κ°λ₯
console.dir(student, { showHidden: true, colors: false, depth: 2 }); //depthλ‘ μ€μ²©λ μ€λΈμ νΈλ₯Ό μ΄λ κΉμ΄ κΉμ§ 보μ¬μ€ κ±΄μ§ μ‘°μ κ°λ₯
console.dir(student, { showHidden: true, colors: false, depth: 0 });
{ name: 'νκΈΈλ', age: 20, company: { name: 'AC' } }
βββββββββββ¬βββββββ¬βββββββββββ
β (index) β name β Values β
βββββββββββΌβββββββΌβββββββββββ€
β name β β 'νκΈΈλ' β
β age β β 20 β
β company β 'AC' β β
βββββββββββ΄βββββββ΄βββββββββββ
{ name: 'νκΈΈλ', age: 20, company: { name: 'AC' } }
{ name: 'νκΈΈλ', age: 20, company: [Object] }
4. μ±λ₯νμΈ : νΉμ μ½λ μνμκ° νμΈ
//measuring time
console.time("for loop");
for (let i = 0; i < 10; i++) {
i++;
}
console.timeEnd("for loop"); //for loop: 0.129ms
5. counting(ν¨μ νΈμΆ νμ)
function a() {
console.count("a function");
}
a();
a();
console.countReset("a function");
a();
a function: 1
a function: 2
a function: 1
6. trace : λλ²κΉ
μ μμ£Ό μ 리ν¨!!!
function f1() {
f2();
}
function f2() {
f3();
}
function f3() {
console.log("f3");
console.trace(); //μ΄ ν¨μκ° μ΄λμλΆν° μ΄λ»κ² λκ° νΈμΆνλμ§λ₯Ό λ³Ό μ μμ
}
f1();
Trace
at f3 (C:\Users\User\gitprogect\NodeJs\1-global\app.js:53:11)
at f2 (C:\Users\User\gitprogect\NodeJs\1-global\app.js:48:3)
at f1 (C:\Users\User\gitprogect\NodeJs\1-global\app.js:44:3)
at Object.<anonymous> (C:\Users\User\gitprogect\NodeJs\1-global\app.js:56:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
νμ½λ
const fs = require("fs");
console.log("logging.....");
console.clear();
// log level : μλ²μμ λ°μνλ μ¬λ¬ μ΄λ²€νΈμ λν΄μ(μλ¬μ μνμ λ°λΌμ)
console.log("log"); //κ°λ°
console.info("info"); //κ°λ°
console.warn("warn"); //경보
console.error("error"); //μλ¬, μ¬μ©μ μλ¬, μμ€ν
μλ¬
//assert : 첫λ²μ§Έ μΈμκ° false μΌλλ§ μΆλ ₯
console.assert(2 === 3, "not same!");
console.assert(2 === 2, "same!");
//print object : 보기 μ’κ² μΆλ ₯
const student = { name: "νκΈΈλ", age: 20, company: { name: "AC" } };
console.log(student);
console.table(student); //λ 보기 μ’κ² ν
μ΄λΈ ννλ‘ μΆλ ₯ κ°λ₯
console.dir(student, { showHidden: true, colors: false, depth: 2 }); //depthλ‘ μ€μ²©λ μ€λΈμ νΈλ₯Ό μ΄λ κΉμ΄ κΉμ§ 보μ¬μ€ κ±΄μ§ μ‘°μ κ°λ₯
console.dir(student, { showHidden: true, colors: false, depth: 0 });
//μ±λ₯νμΈ : νΉμ μ½λ μνμκ° νμΈ
//measuring time
console.time("for loop");
for (let i = 0; i < 10; i++) {
i++;
}
console.timeEnd("for loop");
//counting(ν¨μ νΈμΆ νμ)
function a() {
console.count("a function");
}
a();
a();
console.countReset("a function");
a();
//trace : λλ²κΉ
μ μμ£Ό μ 리ν¨!!!
function f1() {
f2();
}
function f2() {
f3();
}
function f3() {
console.log("f3");
console.trace(); //μ΄ ν¨μκ° μ΄λμλΆν° μ΄λ»κ² λκ° νΈμΆνλμ§λ₯Ό λ³Ό μ μμ
}
f1();
λ‘κ·Έ
log
info
warn
error
Assertion failed: not same!
{ name: 'νκΈΈλ', age: 20, company: { name: 'AC' } }
βββββββββββ¬βββββββ¬βββββββββββ
β (index) β name β Values β
βββββββββββΌβββββββΌβββββββββββ€
β name β β 'νκΈΈλ' β
β age β β 20 β
β company β 'AC' β β
βββββββββββ΄βββββββ΄βββββββββββ
{ name: 'νκΈΈλ', age: 20, company: { name: 'AC' } }
{ name: 'νκΈΈλ', age: 20, company: [Object] }
for loop: 0.129ms
a function: 1
a function: 2
a function: 1
f3
Trace
at f3 (C:\Users\User\gitprogect\NodeJs\1-global\app.js:53:11)
at f2 (C:\Users\User\gitprogect\NodeJs\1-global\app.js:48:3)
at f1 (C:\Users\User\gitprogect\NodeJs\1-global\app.js:44:3)
at Object.<anonymous> (C:\Users\User\gitprogect\NodeJs\1-global\app.js:56:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
'Javascript > Node.js' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Node.js] ν΄λΌμ΄μΈνΈμ μλ²μ κ°λ , AWS ν΄λΌμ°λ μλ² νκ²½ κ΅¬μΆ μ€μ΅ (0) | 2022.05.14 |
---|---|
[Node.js] λ°±μλ κ°λ κΈ°μ΄ μμλͺ¨μ (0) | 2022.05.14 |
[node.js] μ΄κ°λ¨ μλ² λ§λ€κΈ° (2) Node + Express μΉμλ² κΈ°λ³ΈμΈν (0) | 2022.05.14 |
[Node.js] global (0) | 2022.05.14 |
node.js μ΄κ°λ¨ μλ² λ§λ€κΈ° (1) express λΌμ΄λΈλ¬λ¦¬ μ€μΉ (0) | 2022.03.18 |