🪵 การดึง Log ของ JavaScript Engine ใน iBrowe (Dumping JavaScript Engine Logs in iBrowe)
ถ้าคุณต้องการเก็บ Log ภายในของ JavaScript engine (V8) ขณะรัน iBrowe คุณสามารถใช้ logging flags ขณะสั่งเปิดโปรแกรม วิธีนี้มีประโยชน์มากสำหรับการดีบักพฤติกรรมระดับลึกของ V8
🚀 การเปิด iBrowe พร้อมเปิด Logging (Launching iBrowe with Logging Enabled)
ให้รันคำสั่งนี้:
ibrowe --no-sandbox --js-flags=“–log-all --log-file=/path/to/logs/%t.log”
คำสั่งนี้จะเปิดการบันทึก Log แบบเต็มรูปแบบ และจะบันทึก Log ลงในไฟล์ โดยที่ %t จะถูกแทนด้วยเวลา (timestamp) ปัจจุบัน
🧩 ตัวแปรแทนค่าในชื่อไฟล์ Log (Log File Placeholders)
คุณสามารถปรับแต่งชื่อไฟล์ Log ได้ด้วยตัวแปรแทนค่าเหล่านี้:
- %p: หมายถึง Process ID (รหัสโปรเซสปัจจุบัน)
- %t: หมายถึง Timestamp ปัจจุบัน (หน่วยเป็นมิลลิวินาที)
🎯 V8 Logging Flags ที่มีประโยชน์ (Useful V8 Logging Flags)
นอกจาก --log-all ยังมี flag อื่น ๆ ที่ช่วยให้กรองข้อมูล Log ได้สะดวกขึ้น เช่น:
–log-code
–log-function-events
–log-timer-events
–log-snapshot-positions
–log-source-code
–log-maps
ดูคำอธิบาย flag แบบเต็มได้ที่: https://github.com/v8/v8/blob/a802d5aae5a28f7b762d836429d7c1d4da98537e/src/flags/flag-definitions.h#L2207-L2229
🧵 การสร้าง Log เอง (Custom Logging) ใน C++ แบบ printf-style
สำหรับการดีบักขั้นสูง คุณสามารถเขียน Log เองจาก C++ ได้ เช่น:
#include “src/strings/string-stream.h”
HeapStringAllocator allocator; StringStream strstream(&allocator); strstream.Add(“hello log %d”, int_value); strstream.Log(isolate);
อ้างอิง: ดัดแปลงจากเอกสาร Brave และ source code ของ V8: