ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Log ဆိုတာ system/application က ဖြစ်ပျက်ခဲ့တာအားလုံးကို ရေးမှတ်ထားတဲ့ diary ပါ — traditional log file တွေကို /var/log ထဲမှာ (auth.log, syslog စသည်) တွေ့ရနိုင်ပြီး, modern systemd-based distro တွေကတော့ journalctl command နဲ့ centralized binary log ကို ကြည့်ပါတယ်။ journalctl -u <service> က service တစ်ခုချင်းစီရဲ့ log ကိုပဲ filter လုပ်ပြပါတယ် (ဥပမာ journalctl -u nginx)။ journalctl -f ကတော့ tail -f နဲ့ ဆင်တူပြီး live log ကို real-time monitor လုပ်ပါတယ်။ journalctl --since "1 hour ago" ကတော့ အချိန်ကာလ specific ဖြင့် filter လုပ်ချင်တဲ့အခါ သုံးပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Service တစ်ခု start မရ (systemctl status ထဲမှာ 'failed' ပြရင်) journalctl -u <service-name> -n 50 (နောက်ဆုံး line ၅၀) ကို run ပြီး error message အတိအကျ ဖတ်ကြည့်ပါ — 'permission denied', 'port already in use' လို error message တွေက ပြဿနာကို အတိအကျ ညွှန်ပြပေးပါတယ်။ Web server error ဖြစ်နေရင် /var/log/nginx/error.log ကို tail -f ဖြင့် live monitor လုပ်ပြီး, web page ကို ပြန်ဖွင့်ကြည့်ရင်း error ဘယ်အချိန် ပေါ်လာသလဲ တိုက်ရိုက်တွေ့နိုင်ပါတယ်။
အတူတူ terminal ထဲ စမ်းမယ်
journalctl -u nginx -n 50
journalctl -f
journalctl --since "1 hour ago"
tail -f /var/log/nginx/error.logjournalctl -u nginx -n 50 ကို run ရင် nginx service ရဲ့ နောက်ဆုံး log line ၅၀ ကို timestamp တွဲပြီး ပြသမည်။၅ မိနစ် စမ်းကြည့်
journalctl -u ssh -n 20 (သို့) journalctl -n 20 ကို run ကြည့်ပါ (install ရှိတဲ့ system မှာ)။ Log ထဲက timestamp, service name, message column ၃ ခုကို ရှာဖတ်ကြည့်ပါ။
သတိလေးတစ်ချက်
Log ဖိုင်တွေထဲမှာ password, API key, personal data ပါနိုင်ပါတယ် — log ကို public forum (Stack Overflow) ပေါ် copy-paste မလုပ်ခင် sensitive information ဖျက်ထားဖို့ သတိထားပါ။