Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
FastAPIでAOP的ロギングはありなのか?
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
村上優稀
May 21, 2025
Programming
110
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
FastAPIでAOP的ロギングはありなのか?
村上優稀
May 21, 2025
More Decks by 村上優稀
See All by 村上優稀
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
280
Amplify gen2 を使うと何が嬉しいか?
musan
0
20
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
240
DI(依存性注入)
musan
0
67
Other Decks in Programming
See All in Programming
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
690
Intent as Code
shoppingjaws
6
1k
iOSDC2026登壇資料.pdf
riofujimon
0
160
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
710
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
970
自分的「カンファレンスの楽しみ方」
syumai
0
200
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
240
What We Talk About When We Talk About XP
m_seki
2
620
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.2k
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
240
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
160
Featured
See All Featured
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
420
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
Navigating Weather and Climate Data
rabernat
0
520
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
GitHub's CSS Performance
jonrohan
1033
470k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
58k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Transcript
FastAPIでもAOP的ロギングは アリなのか? NCDC 村上
自己紹介 • 村上優稀 • バックエンドエンジニア • 実務経験3年 • 最初の2年はJava、Springを触っていた •
ここ1年はPython、FastAPIを触っている • 今日の発表はちょっと背伸びしてます (マサカリ怖い。。。)
目次 • AOPって何? – Springフレームワーク – 横断的関心事と本質的関心事 • PythonにはAOP的な考え方ないの? •
FastAPIで横断的にロギング処理入れてみた • Pythonの哲学的にどうなのか?
AOPって何? • アスペクト志向プログラミング • 関心の分離を目的としたプログラミングの考え 方 • 横断的な処理を共通化・自動化するための技術 – ログ出力
– トランザクション管理 – 例外処理の一元化 • Springフレームワークなどで取り入れられている
横断的関心事:ログやトランザクション管理、エラー処理 本質的関心事:会員管理や商品管理、注文管理
・共通処理の一元化でコードがスッキリ ・変更が容易で保守性向上 ・本来のビジネスロジックに集中できる(エンジニア1年目にとってとてもありがたかった)
FastAPIにはAOP的な考え方ないの? • FastAPI AOPで検索しても、日本語の記事は ヒットせず。 韓国語と英語の記事がちらほら。 • AOPはプログラミング言語を問わない便利な 考え方だと思ってたけど、Pythonの哲学と相 性悪かったりするのかなと疑問に思った。
• Python AOPで検索したら「デコレータ」が ヒットした
デコレータとは? 関数やクラスの前後に 特定の処理を追加できるPythonの標準機能
関数の前後でログ出すデコレータ実装
FastAPIで簡単なAPIを作ってみて @loggerを関数につける
SwaggerからAPIを実行
AOP的なロギングはとりあえずできた。 Pythonの哲学的にはどうなの? Pythonの「Zen of Python(PEP 20)」に以下のような記述がある Explicit is better than
implicit (明示的は暗黙的よりも良い) @loggerはログ出すんだなとわかるからOKなんじゃないかなと思 いました。 ただ、引数もログに出す場合などは個人情報をログに出すとまず いので、使い方には注意が必要だなと思いました。 @loggerを特定のパッケージ配下の関数全部に適用するような処 理も書けるようだが、だいぶ暗黙的になってしまうので Python的にはなしなのかなと思いました。
ありがとうございました!