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
村上優稀
May 21, 2025
Programming
120
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
300
Amplify gen2 を使うと何が嬉しいか?
musan
0
28
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
270
DI(依存性注入)
musan
0
83
Other Decks in Programming
See All in Programming
AI-Powered Domain-Driven Design
ziobrando
0
320
続・コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions-again
handlename
0
120
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
140
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
190
GraphQL の onError と Nullability のこれから
quramy
0
180
[2026-10-14](C)Re:ゼロから始める異世界生活〜始まりの終わりと終わりの始まり〜
tosite
0
160
Domain-Driven Transformation
hschwentner
2
2.3k
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
370
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
150
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
270
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.7k
気持ちぃ〜角丸 Squircle
ryu1013
0
340
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
410
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
530
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Ethics towards AI in product and experience design
skipperchong
2
440
Paper Plane
katiecoart
PRO
5
54k
Between Models and Reality
mayunak
4
510
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Abbi's Birthday
coloredviolet
4
10k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
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的にはなしなのかなと思いました。
ありがとうございました!