๐ console.log ์กธ์ ! ํ๋ก ๊ฐ๋ฐ์์ ๋๋ฒ๊น ๊ฟํ 5๊ฐ์ง
๊ด๋ฆฌ์
7์ผ ์
๐ console.log ์กธ์ ! ํ๋ก ๊ฐ๋ฐ์์ ๋๋ฒ๊น ๊ฟํ 5๊ฐ์ง
๐ฏ "์์ง๋ console.log๋ง ์ฐ์ธ์?"
์๋ ํ์ธ์! ์ค๋์ ์ ๊ฐ 5๋ ๊ฐ console.log๋ง ์ฐ๋ค๊ฐ ์ต๊ทผ์ ์๊ฒ ๋ ์ถฉ๊ฒฉ์ ์ธ ๋๋ฒ๊น ๋ฐฉ๋ฒ๋ค์ ๊ณต์ ํ๋ ค๊ณ ํฉ๋๋ค.
์์งํ ๊ณ ๋ฐฑํ์๋ฉด, ์ ๋ ์ผ๋ง ์ ๊น์ง ์ด๋ฌ์ด์:
console.log("์ฌ๊ธฐ1");
console.log("์ฌ๊ธฐ2");
console.log("๊ฐ ํ์ธ:", data);
console.log("์ด๊ฑฐ ์คํ๋จ?");
// ... 100๊ฐ์ console.log
๊ทธ๋ฐ๋ฐ ์๋์ด ๊ฐ๋ฐ์๊ฐ ์ ์ฝ๋๋ฅผ ๋ณด๋๋ ํ์จ์ ์ฌ๋ฉด์...
"์ด๊ฑฐ 10์ด๋ฉด ์ฐพ์ ์ ์๋ ๋ฒ๊ทธ์ธ๋ฐ์?" ๋ผ๊ณ ํ๋๋ผ๊ณ ์. ๐ฑ
์ค๋์ ๊ทธ๋ ๋ฐฐ์ด ์ง์ง ํ๋ก๊ฐ ์ฐ๋ ๋๋ฒ๊น ๋น๋ฒ 5๊ฐ์ง๋ฅผ ์๋ ค๋๋ฆด๊ฒ์!
๐ ๊ฟํ 1: debugger ์ค๋จ์ - "console.log๋ ์ด์ ๊ทธ๋ง!"
๊ธฐ์กด ๋ฐฉ์ (์ฃผ๋์ด์ ์ถ)
function calculatePrice(items) {
console.log("ํจ์ ์์");
console.log("items:", items);
const total = items.reduce((sum, item) => {
console.log("ํ์ฌ item:", item);
console.log("ํ์ฌ sum:", sum);
return sum + item.price * item.quantity;
}, 0);
console.log("total:", total);
return total;
}
ํ๋ก์ ๋ฐฉ์ (1์ด ๋๋ฒ๊น )
function calculatePrice(items) {
debugger; // ์ฌ๊ธฐ์ ๋ฉ์ถค! F10์ผ๋ก ํ ์ค์ฉ ์คํ
const total = items.reduce((sum, item) => {
return sum + item.price * item.quantity;
}, 0);
return total;
}
๐ฏ ์ฌ์ฉ๋ฒ:
- ์ฝ๋์
debugger;
์ถ๊ฐ - ๊ฐ๋ฐ์ ๋๊ตฌ ์ด๊ณ ์คํ
- F10 = ๋ค์ ์ค, F11 = ํจ์ ์์ผ๋ก, F8 = ๊ณ์ ์คํ
- ๋ณ์ ์์ ๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด ๊ฐ์ด ๋ณด์!
๐ก ๊ฟํ ์ค์ ๊ฟํ: ์กฐ๊ฑด๋ถ ์ค๋จ์
// ํน์ ์กฐ๊ฑด์ผ ๋๋ง ๋ฉ์ถ๊ณ ์ถ๋ค๋ฉด?
if (user.id === 'problem-user-123') {
debugger; // ๋ฌธ์ ์๋ ์ ์ ์ผ ๋๋ง ๋ฉ์ถค!
}
๐จ ๊ฟํ 2: Chrome DevTools์ ์จ๊ฒจ์ง ๋ณด๋ฌผ๋ค
2-1. Logpoints - "์ฝ๋ ์์ ์์ด ๋ก๊ทธ ์ถ๊ฐ"
์ํฉ: ํ๋ก๋์ ์ฝ๋๋ผ console.log ์ถ๊ฐ ๋ชปํจ
ํด๊ฒฐ:
- Sources ํญ โ ์ค ๋ฒํธ ์ฐํด๋ฆญ
- "Add logpoint" ์ ํ
"User ID:", user.id, "Action:", action
์ ๋ ฅ- ์๋ก๊ณ ์นจ ์์ด ๋ก๊ทธ ํ์ธ!
2-2. DOM ์ค๋จ์ - "๋๊ฐ ๋ด DOM์ ๊ฑด๋๋ ธ๋?"
// ์ด๋ฐ ๊ฒฝํ ์์ผ์์ฃ ?
// "๋ถ๋ช
display: none ํ๋๋ฐ ์ ๋ณด์ด์ง?"
// "๋๊ฐ ์ด ํด๋์ค๋ฅผ ์ญ์ ํ์ง?"
ํด๊ฒฐ๋ฒ:
- Elements ํญ์์ ์์ ์ฐํด๋ฆญ
- "Break on" โ "attribute modifications" ์ ํ
- ์ด์ ๋๊ฐ ๊ฑด๋๋ฆฌ๋ฉด ๋ฐ๋ก ์กํ!
2-3. Copy as Fetch - "Postman ํ์ ์์"
๋คํธ์ํฌ ํญ์์:
- API ์์ฒญ ์ฐํด๋ฆญ
- "Copy" โ "Copy as fetch"
- ์ฝ์์ ๋ถ์ฌ๋ฃ๊ธฐ
- ๋ฐ๋ก ํ ์คํธ!
// ์๋์ผ๋ก ์ด๋ ๊ฒ ๋ณต์ฌ๋จ
fetch("https://api.example.com/users", {
headers: {
"authorization": "Bearer token...",
"content-type": "application/json"
},
body: JSON.stringify({name: "test"}),
method: "POST"
});
๐ป ๊ฟํ 3: VS Code ๋๋ฒ๊ฑฐ - "ํฐ๋ฏธ๋์ ์ด์ ์๋ "
Node.js ๋๋ฒ๊น (๊ฐ์ธํ )
๊ธฐ์กด ๋ฐฉ์:
node app.js
# console.log ์ง์ฅ...
ํ๋ก ๋ฐฉ์:
- VS Code์์ F5 ๋๋ฅด๊ธฐ
- "Node.js" ์ ํ
- ๋!
๋ ํ๋ก ๋ฐฉ์ (์๋ ์ฐ๊ฒฐ):
// package.json
{
"scripts": {
"dev": "node --inspect index.js"
}
}
VS Code ์ค์ :
- Ctrl+Shift+P โ "Debug: Toggle Auto Attach"
- "Always" ์ ํ
- ์ด์ npm run dev๋ง ํ๋ฉด ์๋ ๋๋ฒ๊ฑฐ ์ฐ๊ฒฐ!
React ๋๋ฒ๊น (๋ฆฌ์กํธ ๊ฐ๋ฐ์ ํ๋ !)
// .vscode/launch.json
{
"type": "chrome",
"request": "launch",
"name": "React ๋๋ฒ๊น
",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/src",
"sourceMaps": true
}
์ด์ VS Code์์ React ์ปดํฌ๋ํธ์ ์ค๋จ์ ์ค์ ๊ฐ๋ฅ! ๐
๐ฏ ๊ฟํ 4: ๋ก๊ทธ ๋ ๋ฒจ ํ์ฉ - "console.log ๋์ ์ด๊ฒ!"
์ฃผ๋์ด ์คํ์ผ
console.log("๋ฐ์ดํฐ:", data);
console.log("์๋ฌ!!!:", error);
console.log("๊ฒฝ๊ณ :", warning);
์๋์ด ์คํ์ผ
// ๋ ๋ฒจ๋ณ๋ก ๋ค๋ฅด๊ฒ!
console.debug("๊ฐ๋ฐ ์ค์๋ง ํ์ํ ์ ๋ณด", data);
console.info("์ผ๋ฐ ์ ๋ณด: ์๋ฒ ์์๋จ");
console.warn("โ ๏ธ ๊ฒฝ๊ณ : API ์๋ต ๋๋ฆผ", responseTime);
console.error("โ ์๋ฌ ๋ฐ์:", error);
// ๊ทธ๋ฃน์ผ๋ก ๋ฌถ๊ธฐ
console.group("์ฌ์ฉ์ ์ธ์ฆ ํ๋ก์ธ์ค");
console.log("1. ํ ํฐ ํ์ธ");
console.log("2. ๊ถํ ๊ฒ์ฆ");
console.log("3. ์ธ์
์์ฑ");
console.groupEnd();
// ํ
์ด๋ธ๋ก ๋ณด๊ธฐ (์ด๊ฑฐ ์ง์ง ์ ๊ธฐํจ!)
const users = [
{id: 1, name: "๊น๊ฐ๋ฐ", age: 25},
{id: 2, name: "๋ฐ์ฝ๋ฉ", age: 30}
];
console.table(users); // ํ๋ก ์์๊ฒ ์ถ๋ ฅ๋จ!
// ์๊ฐ ์ธก์
console.time("API ํธ์ถ");
await fetch('/api/users');
console.timeEnd("API ํธ์ถ"); // API ํธ์ถ: 234.5ms
// ์คํ ์ถ์
console.trace("์ฌ๊ธฐ์ ํธ์ถ๋จ");
ํ๋ก๋์ ์ฉ ๋ก๊ฑฐ ์ค์
// ํ๊ฒฝ๋ณ ๋ก๊ทธ ๋ ๋ฒจ ์ค์
const LOG_LEVEL = process.env.NODE_ENV === 'production' ? 'error' : 'debug';
const logger = {
debug: (...args) => LOG_LEVEL === 'debug' && console.debug(...args),
info: (...args) => ['debug', 'info'].includes(LOG_LEVEL) && console.info(...args),
warn: (...args) => ['debug', 'info', 'warn'].includes(LOG_LEVEL) && console.warn(...args),
error: (...args) => console.error(...args) // ์๋ฌ๋ ํญ์ ์ถ๋ ฅ
};
// ์ฌ์ฉ
logger.debug("๊ฐ๋ฐ ํ๊ฒฝ์์๋ง ๋ณด์");
logger.error("๋ชจ๋ ํ๊ฒฝ์์ ๋ณด์");
๐ฅ ๊ฟํ 5: ์ฑ๋ฅ & ๋ฉ๋ชจ๋ฆฌ ๋๋ฒ๊น - "์ ๋๋ฆฐ์ง ์ด์ ์ ์ ์๋ค!"
5-1. Performance ์ธก์
// ์ฑ๋ฅ ์ธก์ ๋งํฌ
performance.mark('myFunction-start');
// ๋ฌด๊ฑฐ์ด ์์
for(let i = 0; i < 1000000; i++) {
// ๋ญ๊ฐ ์ฒ๋ฆฌ
}
performance.mark('myFunction-end');
performance.measure('myFunction', 'myFunction-start', 'myFunction-end');
// ๊ฒฐ๊ณผ ํ์ธ
const measure = performance.getEntriesByName('myFunction')[0];
console.log(`์คํ ์๊ฐ: ${measure.duration}ms`);
5-2. ๋ฉ๋ชจ๋ฆฌ ๋์ ์ฐพ๊ธฐ
์ฆ์:
- ์ฑ์ด ์ ์ ๋๋ ค์ง
- ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ด ๊ณ์ ์ฆ๊ฐ
์ง๋จ๋ฒ:
// ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ์ฒดํฌ
console.log("๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ:", performance.memory);
// ์ฃผ๊ธฐ์ ์ผ๋ก ์ฒดํฌ
setInterval(() => {
const used = performance.memory.usedJSHeapSize / 1048576;
console.log(`ํ์ฌ ๋ฉ๋ชจ๋ฆฌ: ${used.toFixed(2)} MB`);
}, 5000);
Chrome DevTools๋ก ์ฐพ๊ธฐ:
- Memory ํญ โ Heap Snapshot
- ์์ ์ํ
- ๋ค์ Snapshot
- Comparison ๋ณด๊ธฐ
- "Detached DOM" ์ฐพ๊ธฐ โ ์ด๊ฒ ์ฃผ๋ฒ!
5-3. React ์ฑ๋ฅ ๋๋ฒ๊น
// React DevTools Profiler ์ฌ์ฉ
// 1. React DevTools ์ค์น
// 2. Profiler ํญ ํด๋ฆญ
// 3. ๋
นํ ์์ โ ์ก์
์ํ โ ์ค์ง
// 4. ์ด๋ ์ปดํฌ๋ํธ๊ฐ ์ค๋ ๊ฑธ๋ฆฌ๋์ง ๋ฐ๋ก ๋ณด์!
// ์ปดํฌ๋ํธ ๋ ๋๋ง ์ถ์
function MyComponent() {
console.log("MyComponent ๋ ๋๋ง๋จ");
// ์ ๋ฆฌ๋ ๋๋ง๋๋์ง ํ์ธ
useEffect(() => {
console.log("Props ๋ณ๊ฒฝ๋จ:", props);
});
return <div>...</div>;
}
๐ช ๋ณด๋์ค: 2025๋ ์ต์ ๋๋ฒ๊น ๋๊ตฌ๋ค
AI ๋๋ฒ๊น (์ด์ ๋ AI๊ฐ ๋๋ฒ๊น ๋ ํด์ค!)
Chrome DevTools AI Assistant:
- DevTools ์ค์ โ AI Innovations ํ์ฑํ
- ์๋ฌ ๋ฐ์ ์ "Ask AI" ๋ฒํผ ํด๋ฆญ
- AI๊ฐ ์์ธ๊ณผ ํด๊ฒฐ๋ฒ ์ ์!
์ค์ ์์:
// ์๋ฌ: Cannot read property 'name' of undefined
// AI ๋ต๋ณ: "user ๊ฐ์ฒด๊ฐ undefined์
๋๋ค.
// API ์๋ต์ ํ์ธํ๊ฑฐ๋ ์ต์
๋ ์ฒด์ด๋(?.)์ ์ฌ์ฉํ์ธ์"
// ์์ ์ฝ๋ ์ ์
const userName = user?.name || 'Guest';
์๊ฒฉ ๋๋ฒ๊น (์ฌํ๊ทผ๋ฌด ํ์!)
# ์๋ฒ์์ Node.js ์ฑ ์คํ
node --inspect=0.0.0.0:9229 app.js
# ๋ก์ปฌ์์ Chrome ์ด๊ณ
chrome://inspect
# "Configure" โ IP ์ฃผ์ ์ถ๊ฐ
# ์ด์ ์๋ฒ ์ฑ์ ๋ก์ปฌ์์ ๋๋ฒ๊น
!
๐ ์ค์ ๋๋ฒ๊น ์ฒดํฌ๋ฆฌ์คํธ
๋ฒ๊ทธ ๋ฐ์ ์ ์์:
- ์๋ฌ ๋ฉ์์ง ์ฝ๊ธฐ (50%๋ ์ฌ๊ธฐ์ ํด๊ฒฐ)
- debugger๋ก ์ค๋จ์ ์ค์
- ๋ณ์ ๊ฐ ํ์ธ (๋ง์ฐ์ค ํธ๋ฒ)
- ์ฝ ์คํ ํ์ธ (์ด๋์ ํธ์ถ๋๋)
- ๋คํธ์ํฌ ํญ ํ์ธ (API ๋ฌธ์ ?)
- ์ฝ์ ์๋ฌ ํ์ธ
- AI์๊ฒ ๋ฌผ์ด๋ณด๊ธฐ (๋ง์ง๋ง ์๋จ)
๐ฌ ์ค์ ๊ฐ๋ฐ์๋ค์ ๋ฐ์
๊น์ฃผ๋์ด (๊ฒฝ๋ ฅ 1๋ ):
"debugger ํ๋๋ง ์์์ด๋ ์ผ๊ทผ ๋ฐ์ ์ค์์ ๊ฒ ๊ฐ์์... console.log 100๊ฐ ์ฐ๋ฉด์ 3์๊ฐ ๋๋ฒ๊น ํ ์ ๋ ์๋๋ฐ ใ ใ "
๋ฐ์๋์ด (๊ฒฝ๋ ฅ 7๋ ):
"์ ์ ๋ console.log๋ง ์ฐ๋ค๊ฐ ์ ๋ฐฐ๊ฐ debugger ์๋ ค์คฌ์ ๋์ ์ถฉ๊ฒฉ... ์ ์ธ๊ณ์์ฃ "
์ดํ์คํ (๊ฒฝ๋ ฅ 4๋ ):
"Chrome DevTools Logpoint๋ ์ง์ง ํ๋ช ์ ๋๋ค. ํ๋ก๋์ ๋๋ฒ๊น ์ด ์ด๋ ๊ฒ ์ฌ์์ง๋ค๋!"
๐ฏ ์ค๋๋ถํฐ ์ค์ฒํ๊ธฐ
Level 1: ์ด๊ธ (์ค๋ ๋น์ฅ!)
debugger;
์ฌ์ฉํด๋ณด๊ธฐ- console.table() ์จ๋ณด๊ธฐ
- console.time() / timeEnd() ์ฌ์ฉ
Level 2: ์ค๊ธ (์ด๋ฒ ์ฃผ)
- VS Code ๋๋ฒ๊ฑฐ ์ค์
- Chrome DevTools Logpoint
- Performance ํญ ์ฌ์ฉํด๋ณด๊ธฐ
Level 3: ๊ณ ๊ธ (์ด๋ฒ ๋ฌ)
- Memory ํ๋กํ์ผ๋ง
- ์๊ฒฉ ๋๋ฒ๊น ์ค์
- React/Vue DevTools ๋ง์คํฐ
๐ญ ๋ง๋ฌด๋ฆฌ: console.log ์กธ์ ์
์ด์ console.log ์ง์ฅ์์ ๋ฒ์ด๋ ์๊ฐ์ ๋๋ค!
์ฒ์์ ๋ฏ์ค๊ฒ ์ง๋ง, ํ ๋ฒ๋ง ์จ๋ณด๋ฉด "๋ด๊ฐ ์ ์ด๊ฑธ ๋ชฐ๋์ง?" ํ์ค ๊ฑฐ์์.
ํนํ debugger;
ํ๋๋ง ์ ๋๋ก ์จ๋ ๋๋ฒ๊น
์๊ฐ์ด 70%๋ ์ค์ด๋ญ๋๋ค. ์ง์ง๋ก์!
๋ง์ง๋ง์ผ๋ก ์ ๊ฐ ๊ฐ์ฅ ์ข์ํ๋ ๋๋ฒ๊น ๋ช ์ธ ํ๋ ๋จ๊ธฐ๊ณ ๊ฐ๊ฒ์:
"The best debugger is a good night's sleep."
"์ต๊ณ ์ ๋๋ฒ๊ฑฐ๋ ์ถฉ๋ถํ ์๋ฉด์ด๋ค."
๋ฒ๊ทธ๊ฐ ์ ์กํ๋ฉด... ์ผ๋จ ์๊ณ ๋ด์ผ ๋ค์ ๋ด ์๋ค! ๐ด
์ฌ๋ฌ๋ถ๋ง์ ๋๋ฒ๊น ๊ฟํ์ด ์๋ค๋ฉด ๋๊ธ๋ก ๊ณต์ ํด์ฃผ์ธ์! console.log ์กธ์ ํ๊ธฐ๋ ํ์ํฉ๋๋ค! ๐
๋๊ธ 0๊ฐ
์์ง ๋๊ธ์ด ์์ต๋๋ค
์ฒซ ๋ฒ์งธ ๋๊ธ์ ์์ฑํด๋ณด์ธ์!