@book000/node-utils 1.2.30 → 1.2.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/tsconfig.build.tsbuildinfo +1 -0
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +3 -4
  4. package/.ctiignore +0 -3
  5. package/.eslintignore +0 -5
  6. package/.eslintrc.yml +0 -21
  7. package/.github/FUNDING.yml +0 -1
  8. package/.github/workflows/nodejs-ci.yml +0 -18
  9. package/.github/workflows/release.yml +0 -68
  10. package/.gitignore +0 -130
  11. package/.node-version +0 -1
  12. package/.prettierrc.yml +0 -12
  13. package/dist/examples/example-configuration.d.ts +0 -6
  14. package/dist/examples/example-configuration.d.ts.map +0 -1
  15. package/dist/examples/example-configuration.js +0 -29
  16. package/dist/examples/example-configuration.js.map +0 -1
  17. package/dist/examples/example-discord.d.ts +0 -2
  18. package/dist/examples/example-discord.d.ts.map +0 -1
  19. package/dist/examples/example-discord.js +0 -27
  20. package/dist/examples/example-discord.js.map +0 -1
  21. package/dist/examples/example-logger.d.ts +0 -2
  22. package/dist/examples/example-logger.d.ts.map +0 -1
  23. package/dist/examples/example-logger.js +0 -10
  24. package/dist/examples/example-logger.js.map +0 -1
  25. package/dist/examples/main.d.ts +0 -2
  26. package/dist/examples/main.d.ts.map +0 -1
  27. package/dist/examples/main.js +0 -37
  28. package/dist/examples/main.js.map +0 -1
  29. package/renovate.json +0 -12
  30. package/src/configuration.ts +0 -111
  31. package/src/cycle.d.ts +0 -4
  32. package/src/discord.ts +0 -219
  33. package/src/examples/example-configuration.ts +0 -33
  34. package/src/examples/example-discord.ts +0 -28
  35. package/src/examples/example-logger.ts +0 -6
  36. package/src/examples/main.ts +0 -38
  37. package/src/index.ts +0 -3
  38. package/src/logger.ts +0 -168
  39. package/tsconfig.json +0 -32
  40. package/yarn.lock +0 -3323
package/src/logger.ts DELETED
@@ -1,168 +0,0 @@
1
- import winston, { format } from 'winston'
2
- import WinstonDailyRotateFile from 'winston-daily-rotate-file'
3
- import { Format } from 'logform'
4
- import cycle from 'cycle'
5
-
6
- /**
7
- * ロガーラッパークラス
8
- */
9
- export class Logger {
10
- private readonly logger: winston.Logger
11
-
12
- private constructor(logger: winston.Logger) {
13
- this.logger = logger
14
- }
15
-
16
- /**
17
- * デバッグログを出力する
18
- *
19
- * @param message メッセージ
20
- * @param metadata メタデータ
21
- */
22
- public debug(message: string, metadata?: Record<string, unknown>): void {
23
- this.logger.debug(message, metadata || {})
24
- }
25
-
26
- /**
27
- * 情報ログを出力する
28
- *
29
- * @param message メッセージ
30
- * @param metadata メタデータ
31
- */
32
- public info(message: string, metadata?: Record<string, unknown>): void {
33
- this.logger.info(message, metadata || {})
34
- }
35
-
36
- /**
37
- * 警告ログを出力する
38
- *
39
- * @param message メッセージ
40
- * @param error エラー
41
- */
42
- public warn(message: string, error?: Error): void {
43
- this.logger.warn(message, error)
44
- }
45
-
46
- /**
47
- * エラーログを出力する
48
- *
49
- * @param message メッセージ
50
- * @param error エラー
51
- */
52
- public error(message: string, error?: Error): void {
53
- this.logger.error(message, error)
54
- }
55
-
56
- /**
57
- * ロガーを初期化・設定する
58
- *
59
- * 環境変数で以下の設定が可能
60
- * - LOG_LEVEL: ログレベル (デフォルト info)
61
- * - LOG_FILE_LEVEL: ファイル出力のログレベル (デフォルト info)
62
- * - LOG_DIR: ログ出力先 (デフォルト logs)
63
- * - LOG_FILE_MAX_AGE: ログファイルの最大保存期間 (デフォルト 30d)
64
- * - LOG_FILE_FORMAT: ログファイルのフォーマット (デフォルト text)
65
- *
66
- * @param category カテゴリ
67
- * @returns ロガー
68
- */
69
- public static configure(category: string): Logger {
70
- const logLevel = process.env.LOG_LEVEL || 'info'
71
- const logFileLevel = process.env.LOG_FILE_LEVEL || 'info'
72
- const logDirectory = process.env.LOG_DIR || 'logs'
73
- const logFileMaxAge = process.env.LOG_FILE_MAX_AGE || '30d'
74
- const selectLogFileFormat = process.env.LOG_FILE_FORMAT || 'text'
75
-
76
- const textFormat = format.printf((info) => {
77
- const { timestamp, level, message, ...rest } = info
78
- // eslint-disable-next-line unicorn/no-array-reduce
79
- const filteredRest = Object.keys(rest).reduce((accumulator, key) => {
80
- if (key === 'stack') {
81
- return accumulator
82
- }
83
- return {
84
- ...accumulator,
85
- [key]: rest[key],
86
- }
87
- }, {})
88
- const standardLine = [
89
- '[',
90
- timestamp,
91
- '] [',
92
- category ?? '',
93
- category ? '/' : '',
94
- level.toLocaleUpperCase(),
95
- ']: ',
96
- message,
97
- Object.keys(filteredRest).length > 0
98
- ? ` (${JSON.stringify(filteredRest)})`
99
- : '',
100
- ].join('')
101
- const errorLine = info.stack
102
- ? info.stack.split('\n').slice(1).join('\n')
103
- : undefined
104
-
105
- return [standardLine, errorLine].filter((l) => l !== undefined).join('\n')
106
- })
107
- const logFileFormat =
108
- selectLogFileFormat === 'ndjson' ? format.json() : textFormat
109
- const decycleFormat = format((info) => cycle.decycle(info))
110
- const fileFormat = format.combine(
111
- ...([
112
- format.errors({ stack: true }),
113
- selectLogFileFormat === 'ndjson'
114
- ? format.colorize({
115
- message: true,
116
- })
117
- : format.uncolorize(),
118
- decycleFormat(),
119
- format.timestamp({
120
- format: 'YYYY-MM-DD hh:mm:ss.SSS',
121
- }),
122
- logFileFormat,
123
- ].filter((f) => f !== undefined) as Format[])
124
- )
125
- const consoleFormat = format.combine(
126
- ...([
127
- format.colorize({
128
- message: true,
129
- }),
130
- decycleFormat(),
131
- format.timestamp({
132
- format: 'YYYY-MM-DD hh:mm:ss.SSS',
133
- }),
134
- textFormat,
135
- ].filter((f) => f !== undefined) as Format[])
136
- )
137
- const extension = selectLogFileFormat === 'ndjson' ? 'ndjson' : 'log'
138
- const transportRotateFile = new WinstonDailyRotateFile({
139
- level: logFileLevel,
140
- dirname: logDirectory,
141
- filename: `%DATE%.` + extension,
142
- datePattern: 'YYYY-MM-DD',
143
- maxFiles: logFileMaxAge,
144
- format: fileFormat,
145
- auditFile: `${logDirectory}/audit.json`,
146
- })
147
-
148
- const logger = winston.createLogger({
149
- transports: [
150
- new winston.transports.Console({
151
- level: logLevel,
152
- format: consoleFormat,
153
- }),
154
- transportRotateFile,
155
- ],
156
- })
157
- return new Logger(logger)
158
- }
159
- }
160
-
161
- process.on('unhandledRejection', (reason) => {
162
- const logger = Logger.configure('main')
163
- logger.error('unhandledRejection', reason as Error)
164
- })
165
- process.on('uncaughtException', (error) => {
166
- const logger = Logger.configure('main')
167
- logger.error('uncaughtException', error)
168
- })
package/tsconfig.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "ts-node": { "files": true },
3
- "compilerOptions": {
4
- "target": "es2020",
5
- "module": "commonjs",
6
- "moduleResolution": "Node",
7
- "lib": ["ESNext", "esnext.AsyncIterable"],
8
- "outDir": "./dist",
9
- "removeComments": true,
10
- "esModuleInterop": true,
11
- "allowJs": true,
12
- "checkJs": true,
13
- "incremental": true,
14
- "sourceMap": true,
15
- "declaration": true,
16
- "declarationMap": true,
17
- "strict": true,
18
- "noImplicitAny": true,
19
- "strictBindCallApply": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
22
- "noImplicitReturns": true,
23
- "noFallthroughCasesInSwitch": true,
24
- "experimentalDecorators": true,
25
- "baseUrl": ".",
26
- "newLine": "LF",
27
- "paths": {
28
- "@/*": ["src/*"]
29
- }
30
- },
31
- "include": ["src/**/*"]
32
- }