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
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
200
SREの越境 / SRE Collaboration
y0hgi
0
130
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
160
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
970
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
1k
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.7k
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
4
2.5k
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
360
アクセシビリティから考える情報設計
high_g_engineer
0
380
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
Are APIs Still Relevant in the AI Era?
soyuka
0
220
Go のフラットな パッケージに 「ファイル単位の private」を 〜Linter “declscope” を作った話〜
mpyw
0
320
Featured
See All Featured
Bash Introduction
62gerente
615
220k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
520
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
420
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
270
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Designing for humans not robots
tammielis
254
26k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Chasing Engaging Ingredients in Design
codingconduct
0
310
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
500
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
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的にはなしなのかなと思いました。
ありがとうございました!