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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
村上優稀
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
Event is what happens
moro
2
1.6k
contenteditable と日本語入力に向き合う
colorful12
0
220
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4.7k
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
580
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.8k
ChromeでローカルLLM
ryu1013
0
160
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
960
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
190
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
200
オーケストレーション記述言語 Katari
yukikurage
0
200
Railsバージョンを4倍にした話
optim
0
710
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
470
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
490
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Optimizing for Happiness
mojombo
378
71k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
540
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Documentation Writing (for coders)
carmenintech
77
5.6k
Believing is Seeing
oripsolob
1
250
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
59k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
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的にはなしなのかなと思いました。
ありがとうございました!