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
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
290
Amplify gen2 を使うと何が嬉しいか?
musan
0
25
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
260
DI(依存性注入)
musan
0
71
Other Decks in Programming
See All in Programming
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
130
The Rails Doctrine Decade
koic
2
490
phperだってパンチカードでコーディングしたい
o0h
PRO
0
200
setup-vp GitLab対応の裏側
naokihaba
0
150
Rでドレミ/Do-Re-Mi_with_R
florets1
0
120
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
130
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
480
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
350
Jetpack Compose Mechanisms
skydoves
2
350
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.5k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
190
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Marketing to machines
jonoalderson
1
5.8k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
260
Abbi's Birthday
coloredviolet
4
10k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
550
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Site-Speed That Sticks
csswizardry
13
1.5k
The SEO Collaboration Effect
kristinabergwall1
1
590
Large-scale JavaScript Application Architecture
addyosmani
515
110k
How to build a perfect <img>
jonoalderson
1
6.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
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的にはなしなのかなと思いました。
ありがとうございました!