# Monitoring & Logging (Ruby on Rails) > Rails.logger, log levels, Sentry, New Relic, ActiveSupport::Notifications, tracing, correlation IDs, observability - 20 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: Ruby on Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions.md) ## 1. Logger เริ่มต้นที่ใช้ในแอปพลิเคชัน Rails คืออะไร? **คำตอบ** Rails ใช้ Rails.logger เป็นจุดเข้าถึงหลักของระบบ logging โดยค่าเริ่มต้นจะเป็นอินสแตนซ์ของ ActiveSupport::Logger ที่เขียนลงไฟล์อย่าง log/development.log, log/production.log เป็นต้น ขึ้นอยู่กับ environment โดย logger นี้จะถูกตั้งค่าโดยอัตโนมัติเมื่อแอปพลิเคชันเริ่มทำงาน และสามารถเข้าถึงได้จากทุกที่ในโค้ด Rails ## 2. ระดับ log ทั้งห้าที่มีใน Rails จากระดับวิกฤตน้อยที่สุดไปจนถึงวิกฤตมากที่สุดคืออะไร? **คำตอบ** Rails ใช้ระดับ log มาตรฐานห้าระดับ ได้แก่ debug (ข้อมูลโดยละเอียดสำหรับการพัฒนา), info (ข้อมูลการทำงานทั่วไป), warn (คำเตือนที่ไม่ขัดขวางการทำงาน), error (ข้อผิดพลาดที่กู้คืนได้) และ fatal (ข้อผิดพลาดร้ายแรงที่ทำให้หยุดทำงาน) แต่ละระดับจะกรองข้อความที่ระดับต่ำกว่าออกไป ทำให้สามารถปรับระดับความละเอียดได้ตาม environment ## 3. จะกำหนดค่าระดับ log ใน production บน Rails ได้อย่างไร? **คำตอบ** ระดับ log ใน production ถูกกำหนดค่าใน config/environments/production.rb ผ่าน config.log_level ค่าเริ่มต้นคือ :info เพื่อหลีกเลี่ยงการสร้างข้อมูลมากเกินไปใน production นอกจากนี้ยังสามารถกำหนดระดับแบบไดนามิกผ่านตัวแปร environment เช่น ENV.fetch('RAILS_LOG_LEVEL', 'info').to_sym เพื่อความยืดหยุ่นสูงสุดโดยไม่ต้อง deploy ใหม่ ## มีอีก 17 คำถาม - จะบันทึก log ข้อความพร้อมข้อมูลแบบมีโครงสร้างใน Rails เพื่อให้วิเคราะห์ได้ง่ายขึ้นได้อย่างไร? - ความแตกต่างระหว่าง Rails.logger.debug และ Rails.logger.debug { } ที่มี block คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Ruby on Rails อื่นๆ - [พื้นฐาน Ruby](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-basics.md): 25 คำถาม, Junior - [การเขียนโปรแกรมเชิงวัตถุใน Ruby](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-oop.md): 20 คำถาม, Junior - [พื้นฐาน Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-fundamentals.md): 18 คำถาม, Junior - [Routing & Controllers](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/routing-controllers.md): 22 คำถาม, Junior - [พื้นฐาน ActiveRecord](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-basics.md): 25 คำถาม, Junior - [Views และ ERB Templates](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/views-erb-templates.md): 20 คำถาม, Junior - [การเชื่อมโยงของ ActiveRecord](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-associations.md): 24 คำถาม, Mid-Level - [การสอบถาม ActiveRecord ขั้นสูง](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-queries.md): 28 คำถาม, Mid-Level - [ฟอร์ม Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-forms.md): 20 คำถาม, Mid-Level - [การยืนยันตัวตนและการอนุญาต](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/authentication-authorization.md): 22 คำถาม, Mid-Level - [Asset Pipeline สมัยใหม่และ frontend](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-asset-pipeline.md): 18 คำถาม, Mid-Level - [โหมด API ของ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-api-mode.md): 20 คำถาม, Mid-Level - [การทดสอบด้วย RSpec](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-testing-rspec.md): 24 คำถาม, Mid-Level - [ActiveJob & Background Jobs](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-job-background-jobs.md): 20 คำถาม, Mid-Level - [ActionCable & WebSockets](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/action-cable-websockets.md): 18 คำถาม, Mid-Level - [ActionMailer](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/action-mailer.md): 18 คำถาม, Mid-Level - [ActiveStorage](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-storage.md): 20 คำถาม, Mid-Level - [กลยุทธ์การ Caching](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/caching-strategies.md): 20 คำถาม, Mid-Level - [การ Migration ขั้นสูง](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/database-migrations-advanced.md): 20 คำถาม, Mid-Level - [Rails Engines และแอปแบบโมดูลาร์](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-engines-modular-apps.md): 18 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/performance-optimization.md): 26 คำถาม, Senior - [Design Patterns ใน Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-design-patterns.md): 22 คำถาม, Senior - [เมตาโปรแกรมมิงใน Ruby](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-metaprogramming.md): 20 คำถาม, Senior - [ความปลอดภัยของ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-security.md): 22 คำถาม, Senior - [GraphQL กับ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/graphql-rails.md): 20 คำถาม, Senior - [การดีพลอยและโปรดักชัน](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-deployment-production.md): 20 คำถาม, Senior - [กลยุทธ์การอัปเกรด Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-upgrade-strategies.md): 18 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/monitoring-logging