ASC.WePlugins: added support CloudWatch
This commit is contained in:
parent
2f2b1dcf12
commit
3a9fc421c8
@ -3,5 +3,12 @@
|
|||||||
"port": 5014,
|
"port": 5014,
|
||||||
"appsettings": "../../../../config",
|
"appsettings": "../../../../config",
|
||||||
"environment": "Development"
|
"environment": "Development"
|
||||||
}
|
},
|
||||||
|
"aws":{
|
||||||
|
"accessKeyId": "",
|
||||||
|
"secretAccessKey": "",
|
||||||
|
"region": "",
|
||||||
|
"logGroupName": "/docspace/ASC.WebPlugins/instances/${instance-id}/general",
|
||||||
|
"logStreamName": "${guid} - ${date}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,18 +13,21 @@
|
|||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aws-sdk/client-cloudwatch-logs": "^3.199.0",
|
||||||
"@nestjs/common": "^9.0.0",
|
"@nestjs/common": "^9.0.0",
|
||||||
"@nestjs/core": "^9.0.0",
|
"@nestjs/core": "^9.0.0",
|
||||||
"@nestjs/platform-express": "^9.0.0",
|
"@nestjs/platform-express": "^9.0.0",
|
||||||
"@nestjs/typeorm": "^9.0.0",
|
"@nestjs/typeorm": "^9.0.0",
|
||||||
|
"date-and-time": "^2.4.1",
|
||||||
"mysql2": "^2.3.3",
|
"mysql2": "^2.3.3",
|
||||||
"nconf": "^0.12.0",
|
"nconf": "^0.12.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rxjs": "^7.2.0",
|
"rxjs": "^7.2.0",
|
||||||
"typeorm": "^0.3.7",
|
"typeorm": "^0.3.7",
|
||||||
"winston": "^3.8.1",
|
"winston": "^3.8.2",
|
||||||
"winston-daily-rotate-file": "^4.7.1"
|
"winston-cloudwatch": "^6.1.1",
|
||||||
|
"winston-daily-rotate-file": "^4.5.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^9.0.0",
|
"@nestjs/cli": "^9.0.0",
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import * as winston from "winston";
|
import * as winston from "winston";
|
||||||
|
import * as WinstonCloudWatch from "winston-cloudwatch";
|
||||||
|
import * as date from "date-and-time";
|
||||||
|
import * as os from "os";
|
||||||
|
import * as config from "../config";
|
||||||
|
import { randomUUID } from "crypto";
|
||||||
import "winston-daily-rotate-file";
|
import "winston-daily-rotate-file";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
@ -21,6 +26,14 @@ if (!fs.existsSync(dirName)) {
|
|||||||
fs.mkdirSync(dirName);
|
fs.mkdirSync(dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const aws = config.default.get("aws");
|
||||||
|
|
||||||
|
const accessKeyId = aws.accessKeyId;
|
||||||
|
const secretAccessKey = aws.secretAccessKey;
|
||||||
|
const awsRegion = aws.region;
|
||||||
|
const logGroupName = aws.logGroupName;
|
||||||
|
const logStreamName = aws.logStreamName;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
file: {
|
file: {
|
||||||
filename: fileName,
|
filename: fileName,
|
||||||
@ -38,20 +51,62 @@ const options = {
|
|||||||
json: false,
|
json: false,
|
||||||
colorize: true,
|
colorize: true,
|
||||||
},
|
},
|
||||||
|
cloudWatch: {
|
||||||
|
name: 'aws',
|
||||||
|
level: "debug",
|
||||||
|
logGroupName: () => {
|
||||||
|
const hostname = os.hostname();
|
||||||
|
|
||||||
|
return logGroupName.replace("${instance-id}", hostname);
|
||||||
|
},
|
||||||
|
logStreamName: () => {
|
||||||
|
const now = new Date();
|
||||||
|
const guid = randomUUID();
|
||||||
|
const dateAsString = date.format(now, 'YYYY/MM/DDTHH.mm.ss');
|
||||||
|
|
||||||
|
return logStreamName.replace("${guid}", guid)
|
||||||
|
.replace("${date}", dateAsString);
|
||||||
|
},
|
||||||
|
awsRegion: awsRegion,
|
||||||
|
jsonMessage: true,
|
||||||
|
awsOptions: {
|
||||||
|
credentials: {
|
||||||
|
accessKeyId: accessKeyId,
|
||||||
|
secretAccessKey: secretAccessKey
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const transports = [
|
const transports: winston.transport[] = [
|
||||||
new winston.transports.Console(options.console),
|
new winston.transports.Console(options.console),
|
||||||
new winston.transports.DailyRotateFile(options.file),
|
new winston.transports.DailyRotateFile(options.file)
|
||||||
];
|
];
|
||||||
|
|
||||||
export default winston.createLogger({
|
if (aws != null && aws.accessKeyId !== '')
|
||||||
|
{
|
||||||
|
transports.push(new WinstonCloudWatch(options.cloudWatch));
|
||||||
|
}
|
||||||
|
|
||||||
|
const customFormat = winston.format(info => {
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
info.date = date.format(now, 'YYYY-MM-DD HH:mm:ss');
|
||||||
|
info.applicationContext = "ASC.WebPlugins";
|
||||||
|
info.level = info.level.toUpperCase();
|
||||||
|
|
||||||
|
const hostname = os.hostname();
|
||||||
|
|
||||||
|
info["instance-id"] = hostname;
|
||||||
|
|
||||||
|
return info;
|
||||||
|
})();
|
||||||
|
|
||||||
|
module.exports = winston.createLogger({
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
winston.format.timestamp({
|
customFormat,
|
||||||
format: "YYYY-MM-DD HH:mm:ss",
|
winston.format.json()
|
||||||
}),
|
|
||||||
winston.format.json()
|
|
||||||
),
|
),
|
||||||
transports: transports,
|
transports: transports,
|
||||||
exitOnError: false,
|
exitOnError: false,
|
||||||
});
|
});
|
@ -11,7 +11,9 @@ async function bootstrap() {
|
|||||||
try {
|
try {
|
||||||
const app = await NestFactory.create(AppModule, { cors: false });
|
const app = await NestFactory.create(AppModule, { cors: false });
|
||||||
// app.enableCors();
|
// app.enableCors();
|
||||||
await app.listen(port);
|
await app.listen(port, () => {
|
||||||
|
winston.info(`Start WebPlugins Service listening on port ${port} for http`);
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
winston.error(e);
|
winston.error(e);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user