Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit 3f45864

Browse files
authored
Merge pull request #1 from freee/feature/APITEAM-3341_logger
logger追加
2 parents b10d02c + 828e810 commit 3f45864

File tree

21 files changed

+8316
-0
lines changed

21 files changed

+8316
-0
lines changed

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
extends: ['eslint-config-freee-typescript'],
3+
rules: {
4+
'import/no-duplicates': 'off',
5+
'import/namespace': 'off',
6+
'import/no-unresolved': 'off'
7+
},
8+
};

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.idea

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 freee K.K.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
# 会計freee logger
2+
3+
出力をマスキングするためのloggerです。
4+
5+
## できること
6+
7+
- 下記のメソッドを提供します。
8+
- debug
9+
- info
10+
- warn
11+
- error
12+
- fatal
13+
- 下記キーワードがloggerの引数に含まれる時はマスキングします。
14+
- RAW_POST_DATA
15+
- password
16+
- card_number
17+
- cvc
18+
- my_number
19+
- token
20+
- secret
21+
- Authorization
22+
- payee_code
23+
- email
24+
- phone
25+
- street_name
26+
- contact_name
27+
- first_name
28+
- last_name
29+
- given_name
30+
- family_name
31+
- display_name
32+
- transfer_name
33+
- expire_month
34+
- expire_year
35+
- wallet_keys
36+
- wallet_login_key
37+
- wallet_login_secrets
38+
- question
39+
- answer
40+
- approvalcode
41+
- approval_code
42+
- identificationnumber
43+
- identification_number
44+
- application_uid
45+
- application_secret
46+
- credentials
47+
- common_key
48+
- nonce
49+
- certificate
50+
- passphrase
51+
- crt_file
52+
- crt_pass
53+
- amount
54+
- balance
55+
- Signature
56+
- AccessKey
57+
- assertion
58+
- accessToken
59+
- refreshToken
60+
61+
## できないこと
62+
- コンソール以外へのログ出力
63+
64+
## このloggerについて
65+
66+
本 loggerは、β版のステータスとなっており、制限およびバグがある可能性があります。また、このステータスの記載が更新されるまでは、インターフェイスに変更が入る可能性がありますので、ご利用の際はご留意ください。
67+
68+
69+
本 logger を利用する前に下記をご確認ください。
70+
71+
- node上で動作すること
72+
73+
74+
### インストール
75+
76+
該当のプロジェクトディレクトリで以下のコマンドを実行してください。
77+
78+
`npm install freee-logger`
79+
80+
### 開発
81+
82+
- リリースファイル作成時
83+
- lib/index.d.ts, lib/index.js, lib/index.js.mapが更新されます。
84+
85+
```
86+
87+
npm run build
88+
89+
```
90+
91+
- ローカルでの修正、動作確認時
92+
93+
```
94+
npm run build
95+
96+
```
97+
98+
99+
- eslintチェック
100+
101+
```
102+
npm run lint
103+
104+
```
105+
106+
- eslint fix
107+
- 自動修正可能なファイルは修正されます。
108+
109+
```
110+
npm run lint_fix
111+
112+
```
113+
114+
115+
### サンプル
116+
117+
118+
- デフォルトログ出力
119+
120+
```
121+
const logger = getLogger('logger');
122+
const maskingData = {
123+
password: 'pass',
124+
test_1: { accessToken: 'test' },
125+
test2_1: { test2_2: { card_number: 'card_number' } },
126+
test3_1: {
127+
common_key: 'common_key',
128+
test3_2: {
129+
payee_code: 'payee_code',
130+
test3_3: {
131+
street_name: 'street_name',
132+
test3_4: {
133+
AccessKey: 'AccessKey', // eslint-disable-line @typescript-eslint/naming-convention
134+
test3_5: {
135+
first_name: 'first_name',
136+
test3_6: {
137+
last_name: 'last_name',
138+
test3_7: {
139+
expire_year: 'expire_year'
140+
}
141+
}
142+
}
143+
}
144+
}
145+
}
146+
},
147+
'test.test': 'test.test'
148+
};
149+
logger.debug(maskingData);
150+
151+
152+
# キーワードがマスキングされて出力されます。
153+
[2021-04-26T15:36:33.098] [DEBUG] logger - {"password":"****","test_1":{"accessToken":"****"},"test2_1":{"test2_2":{"card_number":"***********"}},"test3_1":{"common_key":"**********","test3_2":{"payee_code":"**********","test3_3":{"street_name":"***********","test3_4":{"AccessKey":"*********","test3_5":{"first_name":"too deep","test3_6":"too deep"}}}}},"test.test":"test.test"}
154+
155+
```
156+
157+
- マスキングキーワードを変更して、ログ出力
158+
- 下記ではキーワードを```test2_1```, ```test.test```のみに変更しています。
159+
160+
```
161+
const maskingFields = ['test2_1', 'test.test'];
162+
const logger = getLogger('masking', maskingFields);
163+
const maskingData = {
164+
password: 'pass',
165+
test_1: { accessToken: 'test' },
166+
test2_1: { test2_2: { card_number: 'card_number' } },
167+
test3_1: {
168+
common_key: 'common_key',
169+
test3_2: {
170+
payee_code: 'payee_code',
171+
test3_3: {
172+
street_name: 'street_name',
173+
test3_4: {
174+
AccessKey: 'AccessKey', // eslint-disable-line @typescript-eslint/naming-convention
175+
test3_5: {
176+
first_name: 'first_name',
177+
test3_6: {
178+
last_name: 'last_name',
179+
test3_7: {
180+
expire_year: 'expire_year'
181+
}
182+
}
183+
}
184+
}
185+
}
186+
}
187+
},
188+
'test.test': 'test.test'
189+
};
190+
logger.debug(maskingData);
191+
192+
193+
# 指定したキーワードがマスキングされて出力されます。
194+
[2021-04-26T15:31:19.035] [DEBUG] masking - {"password":"pass","test_1":{"accessToken":"test"},"test2_1":"***************","test3_1":{"common_key":"common_key","test3_2":{"payee_code":"payee_code","test3_3":{"street_name":"street_name","test3_4":{"AccessKey":"AccessKey","test3_5":{"first_name":"too deep","test3_6":"too deep"}}}}},"test.test":"*********"}
195+
196+
197+
```
198+
199+
200+
- マスキングの深さ(デフォルト5)を変更
201+
- getLoggerの第3引数に深さを指定できます。
202+
- 第3引数のマスキングキーワードをデフォルトのままにする場合はundefinedを指定します。
203+
204+
```
205+
const maxDepth = 6;
206+
const logger = getLogger('masking', undefined, maxDepth);
207+
const maskingData = {
208+
password: 'pass',
209+
test_1: { accessToken: 'test' },
210+
test2_1: { test2_2: { card_number: 'card_number' } },
211+
test3_1: {
212+
common_key: 'common_key',
213+
test3_2: {
214+
payee_code: 'payee_code',
215+
test3_3: {
216+
street_name: 'street_name',
217+
test3_4: {
218+
AccessKey: 'AccessKey', // eslint-disable-line @typescript-eslint/naming-convention
219+
test3_5: {
220+
first_name: 'first_name',
221+
test3_6: {
222+
last_name: 'last_name',
223+
test3_7: {
224+
expire_year: 'expire_year'
225+
}
226+
}
227+
}
228+
}
229+
}
230+
}
231+
},
232+
'test.test': 'test.test'
233+
};
234+
logger.debug(maskingData);
235+
236+
237+
# 指定した改装までマスキングされ、以降は切り落とされます。
238+
[2021-04-26T15:28:42.563] [DEBUG] masking - {"password":"****","test_1":{"accessToken":"****"},"test2_1":{"test2_2":{"card_number":"***********"}},"test3_1":{"common_key":"**********","test3_2":{"payee_code":"**********","test3_3":{"street_name":"***********","test3_4":{"AccessKey":"*********","test3_5":{"first_name":"**********","test3_6":{"last_name":"too deep","test3_7":"too deep"}}}}}},"test.test":"test.test"}
239+
240+
```
241+
242+
243+
## ライセンス
244+
245+
ライセンスについては下記をご参照ください。
246+
247+
[MIT License](./LICENSE)

jest.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
"roots": [
3+
`${__dirname}/src`
4+
],
5+
"transform": {
6+
"^.+\\.tsx?$": "ts-jest"
7+
},
8+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
9+
"moduleFileExtensions": [
10+
"ts",
11+
"tsx",
12+
"js",
13+
"jsx",
14+
"json",
15+
"node"
16+
],
17+
}

lib/.keep

Whitespace-only changes.

lib/index.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
declare module 'freee-logger' {
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
export type Logger = {
4+
debug(message: any, ...args: any[]): void;
5+
6+
info(message: any, ...args: any[]): void;
7+
8+
warn(message: any, ...args: any[]): void;
9+
10+
error(message: any, ...args: any[]): void;
11+
12+
fatal(message: any, ...args: any[]): void;
13+
};
14+
/* eslint-enable @typescript-eslint/no-explicit-any */
15+
16+
export function getLogger(
17+
category: string,
18+
maskingFields?: string[],
19+
maxDepth?: number
20+
): Logger;
21+
}

lib/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)