Upgrade to Pro — share decks privately, control downloads, hide ads and more …

良いデバッグログはプロジェクトの資産である

yhara
July 30, 2016

 良いデバッグログはプロジェクトの資産である

http://eventdots.jp/event/591027

(2016-07-30追記:Rails 5.0からproductionでもDEBUGがデフォルトらしいです)
(2020-09-23追記:https://github.com/rails/rails/pull/39707 INFOに戻りそう)

yhara

July 30, 2016
Tweet

More Decks by yhara

Other Decks in Programming

Transcript

  1. ΞδΣϯμ 1. ͳͥϩά͕ॏཁ͔ 2. ͳͥϩά͕ࢿ࢈ͳͷ͔ 3. Loggerͷ࢖͍ํ 4. ϩάͷೖΕํ 5.

    ϩάΛಡΈ΍͘͢͢Δ޻෉ Fluentd Meetup in Matsue (2016-07-30) 2
  2. ࣗݾ঺հ • @yhara (twi,er, github) • ࣎լݝ→দߐ (2008ʙ) • (ג)ωοτϫʔΫԠ༻௨৴ݚڀॴ

    • Rubyͷ·ͭ΋ͱ͞Μͷ͍Δձࣾ Fluentd Meetup in Matsue (2016-07-30) 3
  3. LoggerΛ࢖ͬͨํ͕͍͍ཧ༝(2) • ग़ྗΛ·ͱΊͯ੔ܗͰ͖Δ(forma(er) σϑΥϧτ I, [2016-07-27T21:50:08.054189 #50431] INFO -- :

    ىಈ͠·ͨ͠ ྫ̍ 2016-07-27 21:50:08 +0900 [INFO] ىಈ͠·ͨ͠ ྫ̎ {"time":"2016-07-27 21:50:08 +0900","level":"INFO","msg":"ىಈ͠·ͨ͠"} Fluentd Meetup in Matsue (2016-07-30) 30
  4. Ͳͷϩά͔ΒೖΕΔ͔ʁ • FATAL • ERROR • WARN • INFO •

    DEBUG Fluentd Meetup in Matsue (2016-07-30) 34
  5. Ͳͷϩά͔ΒೖΕΔ͔ʁ • FATAL • ERROR • WARN • INFO •

    DEBUG Fluentd Meetup in Matsue (2016-07-30) 35
  6. INFOϩάΛೖΕΔ • ࣮گͷΑ͏ʹॻ͘ • ʮαʔόʹ઀ଓ͠·ͨ͠ʯ • ʮϢʔβΛ࡞੒͠·͢ʯ • ʮઓಆΛ։࢝͠·͢ʯ •

    σόοάͷى఺ʹͳΔ • ʮͲ͜·Ͱਖ਼ৗ͔ͩͬͨʯ͕Θ͔Δ Fluentd Meetup in Matsue (2016-07-30) 36
  7. INFOΛೖΕΔ΂͖৔ॴ • ॲཧͷઅ໨ • ྫ) όονॲཧͳΒɺ1߲໨ਐΉ͝ͱͱ͔ • "ϑΝΠϧΛૹ৴͠·ͨ͠ [12/30]" •

    ঢ়ଶ͕มΘͬͨͱ͖ • ྫ) ήʔϜϓϩάϥϜͳΒɺը໘͕ભҠͨ͠ͱ͖ Fluentd Meetup in Matsue (2016-07-30) 37
  8. INFOϩάΛೖΕΔϝϦοτ • ʮ͜ͷϝιου͸ԿΛ͢Δͷ͔ʯΛݟ௚͢ػձʹͳΔ class Player # ๆଧͪͰ߈ܸ͢Δ def mineuchi @message

    = "҆৺͠Ζɺๆଧͪ͡Ό" ... if ... logger.info("ఢ#{name}Λࡴ͠·ͨ͠") ... end Fluentd Meetup in Matsue (2016-07-30) 41
  9. DEBUGϩάΛೖΕΔ • ม਺ͷ஋ͳͲΛग़ྗ͢Δɺ͕ • logger.debug("x: #{x}, y: #{y}") • શ෦Λίϛοτͯ͠͸͍͚ͳ͍

    • ϩά͕ग़͗͢ΔͱअຐʹͳΔ(ಡΊͳ͘ͳΔ)͔ Β • ࣍΋࢖͍ͦ͏ɺͱ͍͏΋ͷ͚ͩίϛοτ͢Δ Fluentd Meetup in Matsue (2016-07-30) 42
  10. INFOͱDEBUGͷ࢖͍෼͚ͷྫ def connect_server ... @server = ... ... logger.info("αʔόʹ઀ଓ͠·ͨ͠(host: #{@host})")

    end • "Cannot connect to server" Έ͍ͨͳྫ֎͕ग़ͨͱ͢Δ • @host͕ؒҧ͍ͬͯΔʁ • @host͸߹ͬͯΔ͕αʔό͕མ͍ͪͯΔʁ Fluentd Meetup in Matsue (2016-07-30) 44
  11. INFOͱDEBUGͷ࢖͍෼͚ͷྫ def connect_server logger.debug("αʔόʹ઀ଓ͠·͢(host: #{@host})") ... @server = ... ...

    logger.info("αʔόʹ઀ଓ͠·ͨ͠(host: #{@host})") end Fluentd Meetup in Matsue (2016-07-30) 45
  12. ࠨ୺Λἧ͑Δ ! 2016-07-30 01:02:03 [foo/foo.swift] ॲཧAΛߦ͍·͢ 2016-07-30 01:02:04 [bar.swift] ॲཧBΛߦ͍·ͨ͠

    ! 2016-07-30 01:02:03 ॲཧAΛߦ͍·͢ [foo/foo.swift] 2016-07-30 01:02:04 ॲཧBΛߦ͍·ͨ͠ [bar.swift] Fluentd Meetup in Matsue (2016-07-30) 49
  13. ه߸Λ͏·͘࢖͏ ! 2016-07-30 01:02:03 ຯํ1͕ఢAΛ߈ܸ͠·ͨ͠ 2016-07-30 01:02:04 ఢB͕ຯํ2Λ߈ܸ͠·ͨ͠ ! 2016-07-30

    01:02:03 [ຯํ1 -> ఢA] 2016-07-30 01:02:04 [ຯํ2 <- ఢB] • จষͰͳ͍ͱ͍͚ͳ͍Θ͚͡Όͳ͍ • ঢ়گ͕͙͢೺ѲͰ͖Δͷ͕ྑ͍ϩά Fluentd Meetup in Matsue (2016-07-30) 51
  14. ద౓ʹ؆ܿʹ • ׂΓࢉͨ͋͠ͱ͸ɺformatΛ࢖ͬͯద౰ͳਫ਼౓ʹ ͢Δ msg = format("Sent files (%.2f records/sec)",

    n_records/dt) logger.info(msg) 2016-07-30 01:02:03 Sent files (202.38 records/sec) Fluentd Meetup in Matsue (2016-07-30) 54
  15. ద౓ʹ؆ܿʹ • νʔϜϝϯόʔ͕ཧղͰ͖ΔͳΒɺͦͷൣғͰ؆ ܿʹͯ͠Α͍ • ྫɿʮrpsʯͰ௨͡ΔͳΒͦΕͰ΋Α͍ 2016-07-30 01:02:03 Sent files

    (202.37 records/sec) ɹ↓ 2016-07-30 01:02:03 Sent files (202.37 rps) Fluentd Meetup in Matsue (2016-07-30) 58
  16. FATAL/ERROR/WARN • FATAL: ϓϩάϥϜ͕ଓ͚ΒΕͳ͍Α͏ͳக໋తΤϥʔ • ͍͍ͩͨERRORͰ୅༻͕ͪ͠ • fluentdͰ΋࢖ͬͯͳ͍ͬΆ͍ • ERROR:

    Τϥʔ • WARN: ܯࠂ • ΤϥʔͰ͸ͳ͍͕ؾʹͨ͠΄͏͕ྑ͍΋ͷ Fluentd Meetup in Matsue (2016-07-30) 61
  17. ERRORͳͷ͔INFOͳͷ͔໰୊ def find_user(name) if (user = @database.find(name)) return user else

    logger.error("Ϣʔβ#{name}͕ݟ͔ͭΓ·ͤΜͰͨ͠") return nil end end • ʮERRORϩά͕ग़ͯͳ͍͔ຖ೔֬ೝ͢ΔʯΈ͍ͨͳӡ ༻ͳΒɺINFO΍DEBUG͕ద੾͔΋͠Εͳ͍ • ͦͷ΁Μ͸͋͘·ͰϓϩδΣΫτ࣍ୈ Fluentd Meetup in Matsue (2016-07-30) 62
  18. ྫ֎Λه࿥͢Δ • ERRORϩάͷ୅දྫ • ҎԼ͸ςϯϓϨ begin MyProgram.new.main rescue Exception =>

    ex LOGGER.error("#{ex.class}: #{ex.message}") ex.backtrace.each do |line| LOGGER.error(line) end raise ex end Fluentd Meetup in Matsue (2016-07-30) 63
  19. ྫ֎Λه࿥͢Δ • Ұݟ؆͕ܿͩ…ʁ begin MyProgram.new.main rescue Exception => ex LOGGER.error("#{ex.class}:

    #{ex.message} "+ ex.backtrace.join('\n')) raise ex end • ϩάʹվߦ(\n)ΛೖΕΔͱɺ͋ͱ͔ΒϓϩάϥϜͰ ղੳ͢Δͷ͕໘౗ͳͷͰ͓͢͢Ί͠ͳ͍ • ϓϩηε͕ෳ਺͋Δͱߦ͕ࠞͬͯ͟෼͔Βͳ͘ͳͬͨΓͱ͔ Fluentd Meetup in Matsue (2016-07-30) 64