@zwa73/utils 1.0.26 → 1.0.27
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.
- package/dist/UtilCom.js +49 -101
- package/dist/UtilFileTools.d.ts +79 -0
- package/dist/UtilFileTools.js +191 -0
- package/dist/UtilFunctions.d.ts +1 -79
- package/dist/UtilFunctions.js +1 -188
- package/dist/UtilInterfaces.d.ts +0 -12
- package/dist/UtilLogger.d.ts +115 -0
- package/dist/UtilLogger.js +249 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +4 -2
- package/src/UtilCom.ts +51 -109
- package/src/UtilFileTools.ts +224 -0
- package/src/UtilFunctions.ts +1 -218
- package/src/UtilInterfaces.ts +0 -14
- package/src/UtilLogger.ts +258 -0
- package/src/index.ts +3 -1
- package/test.js +16 -3
- package/testAndCompile.bat +4 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as winston from 'winston';
|
|
3
|
+
import * as DailyRotateFile from 'winston-daily-rotate-file';
|
|
4
|
+
|
|
5
|
+
/**log等级 undefined相当于 silly */
|
|
6
|
+
export type LogLevel = "fatal"|"error"|"warn"|"info"|"http"|"verbose"|"debug"|"silly"|undefined;
|
|
7
|
+
const logLevels = {
|
|
8
|
+
fatal: 0,
|
|
9
|
+
error: 1,
|
|
10
|
+
warn: 2,
|
|
11
|
+
info: 3,
|
|
12
|
+
http: 4,
|
|
13
|
+
verbose: 5,
|
|
14
|
+
debug: 6,
|
|
15
|
+
silly: 7
|
|
16
|
+
};
|
|
17
|
+
const colorizer = winston.format.colorize();
|
|
18
|
+
colorizer.addColors({
|
|
19
|
+
fatal: 'bold yellow redBG',
|
|
20
|
+
error: 'bold yellow',
|
|
21
|
+
warn: 'yellow',
|
|
22
|
+
info: 'white',
|
|
23
|
+
debug: 'bold cyan',
|
|
24
|
+
silly: 'bold magenta'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export class SLogger{
|
|
28
|
+
/**获取一个Logger,如不存在则用默认参数创建
|
|
29
|
+
* @param {string} name - logger的名称 默认default
|
|
30
|
+
* @returns {SLogger} - 获取的logger
|
|
31
|
+
*/
|
|
32
|
+
static getLogger(name:string="default"):SLogger{
|
|
33
|
+
let out = SLogger.loggerTable[name];
|
|
34
|
+
if(out==null){
|
|
35
|
+
SLogger.createLogger(name);
|
|
36
|
+
out = SLogger.loggerTable[name];
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/**创建Logger
|
|
41
|
+
* @param {string} name - logger的名称 默认default
|
|
42
|
+
* @param {LogLevel} consoleLevel - 输出到控制台的最低等级 默认info
|
|
43
|
+
* @param {string} outFloder - log的输出文件夹路径 如./log/
|
|
44
|
+
* @param {LogLevel} fileLevel - 输出到文件的最低等级 默认info
|
|
45
|
+
* @returns {SLogger} - 创建完成的logger
|
|
46
|
+
*/
|
|
47
|
+
static createLogger(name:string="default",consoleLevel:LogLevel="info",outFloder?:string,fileLevel:LogLevel="info"):SLogger{
|
|
48
|
+
const transports:winston.transport[]=[];
|
|
49
|
+
if(outFloder!=null){
|
|
50
|
+
const fileFormat = winston.format.combine(
|
|
51
|
+
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
52
|
+
winston.format.printf(info => `[${info.timestamp}] [${info.level.toUpperCase()}]: ${info.message}`),
|
|
53
|
+
);
|
|
54
|
+
transports.push(new DailyRotateFile({
|
|
55
|
+
filename: path.join(outFloder,'log-%DATE%.txt'),
|
|
56
|
+
datePattern: 'YYYY-MM-DD',
|
|
57
|
+
level:fileLevel,
|
|
58
|
+
format:fileFormat,
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
const consoleFormat = winston.format.combine(
|
|
62
|
+
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
63
|
+
winston.format.printf(info => {
|
|
64
|
+
const level = info.level.toUpperCase();
|
|
65
|
+
const message = info.message.toString();
|
|
66
|
+
const colorizedLevel = colorizer.colorize(info.level, level);
|
|
67
|
+
const colorizedMessage = colorizer.colorize(info.level, message);
|
|
68
|
+
return `[${info.timestamp}] [${colorizedLevel}]: ${colorizedMessage}`;
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
transports.push(new winston.transports.Console({
|
|
72
|
+
level: consoleLevel,
|
|
73
|
+
format:consoleFormat,
|
|
74
|
+
}));
|
|
75
|
+
const logger = winston.createLogger({
|
|
76
|
+
levels:logLevels,
|
|
77
|
+
transports: transports,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const out = new SLogger();
|
|
81
|
+
out._logger = logger;
|
|
82
|
+
|
|
83
|
+
if(SLogger.loggerTable[name]!=null){
|
|
84
|
+
let old = SLogger.loggerTable[name];
|
|
85
|
+
old._logger.transports.forEach(tp=>{
|
|
86
|
+
if(tp.close!=null) tp.close();
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
SLogger.loggerTable[name] = out;
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
private constructor(){}
|
|
94
|
+
private _logger:winston.Logger = null as any as winston.Logger;
|
|
95
|
+
/**记录Logger的表 */
|
|
96
|
+
private static readonly loggerTable:Record<string,SLogger> = {};
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
//———————————————————— function ——————————————————————//
|
|
101
|
+
/**产生一条对应等级的log 返回自身
|
|
102
|
+
* @param {LogLevel} level - log等级
|
|
103
|
+
* @param {Array<any>} messages - log消息
|
|
104
|
+
* @returns {SLogger} - 自身
|
|
105
|
+
*/
|
|
106
|
+
log(level:LogLevel,...messages:Array<any>):SLogger{
|
|
107
|
+
level = level||"silly";
|
|
108
|
+
let strMessages:Array<string> = [];
|
|
109
|
+
for(let message of messages){
|
|
110
|
+
let out:string;
|
|
111
|
+
if(message == null)
|
|
112
|
+
out = `[type:${typeof message}] ${typeof message}`;
|
|
113
|
+
else if(typeof message!=="string")
|
|
114
|
+
out=`[type:${typeof message}] ${message.toString()}`;
|
|
115
|
+
else out = message;
|
|
116
|
+
strMessages.push(out);
|
|
117
|
+
}
|
|
118
|
+
if(messages.length>1) strMessages.unshift("");
|
|
119
|
+
let outMessage = strMessages.join("\n - ");
|
|
120
|
+
this._logger.log(level,outMessage);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
/**产生一条fatal等级的log 返回自身
|
|
124
|
+
* @param {Array<any>} messages - log消息
|
|
125
|
+
* @returns {SLogger} - 自身
|
|
126
|
+
*/
|
|
127
|
+
fatal(...messages:Array<any>):SLogger {
|
|
128
|
+
return this.log("fatal",...messages);;
|
|
129
|
+
}
|
|
130
|
+
/**产生一条error等级的log 返回自身
|
|
131
|
+
* @param {Array<any>} messages - log消息
|
|
132
|
+
* @returns {SLogger} - 自身
|
|
133
|
+
*/
|
|
134
|
+
error(...messages:Array<any>):SLogger {
|
|
135
|
+
return this.log("error",...messages);;
|
|
136
|
+
}
|
|
137
|
+
/**产生一条warn等级的log 返回自身
|
|
138
|
+
* @param {Array<any>} messages - log消息
|
|
139
|
+
* @returns {SLogger} - 自身
|
|
140
|
+
*/
|
|
141
|
+
warn(...messages:Array<any>):SLogger {
|
|
142
|
+
return this.log("warn",...messages);;
|
|
143
|
+
}
|
|
144
|
+
/**产生一条info等级的log 返回自身
|
|
145
|
+
* @param {Array<any>} messages - log消息
|
|
146
|
+
* @returns {SLogger} - 自身
|
|
147
|
+
*/
|
|
148
|
+
info(...messages:Array<any>):SLogger {
|
|
149
|
+
return this.log("info",...messages);
|
|
150
|
+
}
|
|
151
|
+
/**产生一条http等级的log 返回自身
|
|
152
|
+
* @param {Array<any>} messages - log消息
|
|
153
|
+
* @returns {SLogger} - 自身
|
|
154
|
+
*/
|
|
155
|
+
http(...messages:Array<any>):SLogger {
|
|
156
|
+
return this.log("http",...messages);
|
|
157
|
+
}
|
|
158
|
+
/**产生一条verbose等级的log 返回自身
|
|
159
|
+
* @param {Array<any>} messages - log消息
|
|
160
|
+
* @returns {SLogger} - 自身
|
|
161
|
+
*/
|
|
162
|
+
verbose(...messages:Array<any>):SLogger {
|
|
163
|
+
return this.log("verbose",...messages);
|
|
164
|
+
}
|
|
165
|
+
/**产生一条debug等级的log 返回自身
|
|
166
|
+
* @param {Array<any>} messages - log消息
|
|
167
|
+
* @returns {SLogger} - 自身
|
|
168
|
+
*/
|
|
169
|
+
debug(...messages:Array<any>):SLogger {
|
|
170
|
+
return this.log("debug",...messages);
|
|
171
|
+
}
|
|
172
|
+
/**产生一条silly等级的log 返回自身
|
|
173
|
+
* @param {Array<any>} messages - log消息
|
|
174
|
+
* @returns {SLogger} - 自身
|
|
175
|
+
*/
|
|
176
|
+
silly(...messages:Array<any>):SLogger {
|
|
177
|
+
return this.log("silly",...messages);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
//———————————————————— static ——————————————————————//
|
|
183
|
+
/**名称为default的slogger实例 */
|
|
184
|
+
private static get defaultInstance():SLogger{
|
|
185
|
+
if(SLogger.loggerTable.default==null)
|
|
186
|
+
SLogger.createLogger();
|
|
187
|
+
return SLogger.loggerTable.default;
|
|
188
|
+
}
|
|
189
|
+
/**让名称为default的logger 产生一条对应等级的log 返回自身
|
|
190
|
+
* @param {LogLevel} level - log等级
|
|
191
|
+
* @param {Array<any>} messages - log消息
|
|
192
|
+
* @returns {SLogger} - 自身
|
|
193
|
+
*/
|
|
194
|
+
static log(level: LogLevel, ...messages:Array<any>):SLogger{
|
|
195
|
+
level = level||"silly";
|
|
196
|
+
this.defaultInstance.log(level,...messages);
|
|
197
|
+
return this.defaultInstance;
|
|
198
|
+
}
|
|
199
|
+
/**让名称为default的logger 产生一条fatal等级的log 返回自身
|
|
200
|
+
* @param {Array<any>} messages - log消息
|
|
201
|
+
* @returns {SLogger} - 自身
|
|
202
|
+
*/
|
|
203
|
+
static fatal(...messages:Array<any>):SLogger {
|
|
204
|
+
return this.log("fatal",...messages);;
|
|
205
|
+
}
|
|
206
|
+
/**让名称为default的logger 产生一条error等级的log 返回自身
|
|
207
|
+
* @param {Array<any>} messages - log消息
|
|
208
|
+
* @returns {SLogger} - 自身
|
|
209
|
+
*/
|
|
210
|
+
static error(...messages:Array<any>):SLogger {
|
|
211
|
+
return this.log("error",...messages);;
|
|
212
|
+
}
|
|
213
|
+
/**让名称为default的logger 产生一条warn等级的log 返回自身
|
|
214
|
+
* @param {Array<any>} messages - log消息
|
|
215
|
+
* @returns {SLogger} - 自身
|
|
216
|
+
*/
|
|
217
|
+
static warn(...messages:Array<any>):SLogger {
|
|
218
|
+
return this.log("warn",...messages);;
|
|
219
|
+
}
|
|
220
|
+
/**让名称为default的logger 产生一条info等级的log 返回自身
|
|
221
|
+
* @param {Array<any>} messages - log消息
|
|
222
|
+
* @returns {SLogger} - 自身
|
|
223
|
+
*/
|
|
224
|
+
static info(...messages:Array<any>):SLogger {
|
|
225
|
+
return this.log("info",...messages);
|
|
226
|
+
}
|
|
227
|
+
/**让名称为default的logger 产生一条http等级的log 返回自身
|
|
228
|
+
* @param {Array<any>} messages - log消息
|
|
229
|
+
* @returns {SLogger} - 自身
|
|
230
|
+
*/
|
|
231
|
+
static http(...messages:Array<any>):SLogger {
|
|
232
|
+
return this.log("http",...messages);
|
|
233
|
+
}
|
|
234
|
+
/**让名称为default的logger 产生一条verbose等级的log 返回自身
|
|
235
|
+
* @param {Array<any>} messages - log消息
|
|
236
|
+
* @returns {SLogger} - 自身
|
|
237
|
+
*/
|
|
238
|
+
static verbose(...messages:Array<any>):SLogger {
|
|
239
|
+
return this.log("verbose",...messages);
|
|
240
|
+
}
|
|
241
|
+
/**让名称为default的logger 产生一条debug等级的log 返回自身
|
|
242
|
+
* @param {Array<any>} messages - log消息
|
|
243
|
+
* @returns {SLogger} - 自身
|
|
244
|
+
*/
|
|
245
|
+
static debug(...messages:Array<any>):SLogger {
|
|
246
|
+
return this.log("debug",...messages);
|
|
247
|
+
}
|
|
248
|
+
/**让名称为default的logger 产生一条silly等级的log 返回自身
|
|
249
|
+
* @param {Array<any>} messages - log消息
|
|
250
|
+
* @returns {SLogger} - 自身
|
|
251
|
+
*/
|
|
252
|
+
static silly(...messages:Array<any>):SLogger {
|
|
253
|
+
return this.log("silly",...messages);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
package/src/index.ts
CHANGED
package/test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
let {SList,SHashMap,SEntry,SFfmpegTool,fileSearch,sleep} = require('./dist');
|
|
1
|
+
let {SList,SHashMap,SEntry,SFfmpegTool,fileSearch,sleep,SLogger} = require('./dist');
|
|
2
2
|
|
|
3
3
|
let slist = new SList([1,2,3,3,4,5,6]);
|
|
4
4
|
slist.each(val => console.log(val));
|
|
@@ -15,9 +15,9 @@ for(let {key,value} of map)
|
|
|
15
15
|
async function main(){
|
|
16
16
|
//SFfmpegTool.setFfmpegPath("E:/系统工具/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe");
|
|
17
17
|
//console.log(111111111111)
|
|
18
|
-
let data = await SFfmpegTool.getAudioMetaData("input.wav");
|
|
18
|
+
//let data = await SFfmpegTool.getAudioMetaData("input.wav");
|
|
19
19
|
//console.log(22)
|
|
20
|
-
console.log(data);
|
|
20
|
+
//console.log(data);
|
|
21
21
|
//
|
|
22
22
|
//let fileMap = fileSearch("F:/Sosarciel/SoulTide-Collection-VITS-TrainingSet/TrainingSet/Akaset/sliced_audio",'.*\\.wav');
|
|
23
23
|
//let ioMap = {};
|
|
@@ -28,6 +28,19 @@ async function main(){
|
|
|
28
28
|
//console.log(ioMap)
|
|
29
29
|
//await SFfmpegTool.resampleMP(ioMap)
|
|
30
30
|
}
|
|
31
|
+
|
|
31
32
|
main();
|
|
33
|
+
let a= {a:1};
|
|
34
|
+
SLogger.createLogger("default","silly")
|
|
35
|
+
SLogger.fatal('This is an fatal message');
|
|
36
|
+
SLogger.error('This is an error message');
|
|
37
|
+
SLogger.warn('This is a warning message');
|
|
38
|
+
SLogger.info('This is an info message');
|
|
39
|
+
SLogger.http('This is an http message');
|
|
40
|
+
SLogger.verbose('This is a verbose message');
|
|
41
|
+
SLogger.debug('This is a debug message');
|
|
42
|
+
SLogger.silly('This is a silly message');
|
|
32
43
|
|
|
44
|
+
SLogger.info('This is an info message',123,true);
|
|
45
|
+
SLogger.info([1,2,3,4]);
|
|
33
46
|
|