ASC.UrlShortener: added support CloudWatch
This commit is contained in:
parent
41ad5643ec
commit
68e3f26d90
@ -1,35 +1,14 @@
|
|||||||
/*
|
const winston = require("winston"),
|
||||||
*
|
WinstonCloudWatch = require('winston-cloudwatch');
|
||||||
* (c) Copyright Ascensio System Limited 2010-2020
|
|
||||||
*
|
|
||||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
||||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
||||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
||||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
||||||
*
|
|
||||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
||||||
*
|
|
||||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
||||||
*
|
|
||||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
||||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
||||||
*
|
|
||||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
||||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
||||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
||||||
* in every copy of the program you distribute.
|
|
||||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
require("winston-daily-rotate-file");
|
||||||
|
|
||||||
const winston = require('winston');
|
const path = require("path");
|
||||||
require('winston-daily-rotate-file');
|
const config = require("../config");
|
||||||
|
const fs = require("fs");
|
||||||
const path = require('path');
|
const os = require("os");
|
||||||
const config = require('../config');
|
const { randomUUID } = require('crypto');
|
||||||
const fs = require('fs');
|
const date = require('date-and-time');
|
||||||
|
|
||||||
let logpath = config.get("logPath");
|
let logpath = config.get("logPath");
|
||||||
if(logpath != null)
|
if(logpath != null)
|
||||||
@ -39,28 +18,99 @@ if(logpath != null)
|
|||||||
logpath = path.join(__dirname, "..", logpath);
|
logpath = path.join(__dirname, "..", logpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fileName = logpath ? path.join(logpath, "web.shorturl.%DATE%.log") : path.join(__dirname, "..", "Logs", "web.shorturl.%DATE%.log");
|
|
||||||
|
const fileName = logpath ? path.join(logpath, "web.shorturl.%DATE%.log") : path.join(__dirname, "..", "..", "..", "Logs", "web.shorturl.%DATE%.log");
|
||||||
const dirName = path.dirname(fileName);
|
const dirName = path.dirname(fileName);
|
||||||
|
|
||||||
|
const aws = config.get("aws");
|
||||||
|
|
||||||
|
const accessKeyId = aws.accessKeyId;
|
||||||
|
const secretAccessKey = aws.secretAccessKey;
|
||||||
|
const awsRegion = aws.region;
|
||||||
|
const logGroupName = aws.logGroupName;
|
||||||
|
const logStreamName = aws.logStreamName;
|
||||||
|
|
||||||
if (!fs.existsSync(dirName)) {
|
if (!fs.existsSync(dirName)) {
|
||||||
fs.mkdirSync(dirName);
|
fs.mkdirSync(dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileTransport = new (winston.transports.DailyRotateFile)({
|
var options = {
|
||||||
|
file: {
|
||||||
filename: fileName,
|
filename: fileName,
|
||||||
datePattern: "MM-DD",
|
datePattern: "MM-DD",
|
||||||
handleExceptions: true,
|
handleExceptions: true,
|
||||||
humanReadableUnhandledException: true,
|
humanReadableUnhandledException: true,
|
||||||
zippedArchive: true,
|
zippedArchive: true,
|
||||||
maxSize: '50m',
|
maxSize: "50m",
|
||||||
maxFiles: '30d'
|
maxFiles: "30d",
|
||||||
});
|
json: true,
|
||||||
|
},
|
||||||
|
console: {
|
||||||
|
level: "debug",
|
||||||
|
handleExceptions: true,
|
||||||
|
json: false,
|
||||||
|
colorize: true,
|
||||||
|
},
|
||||||
|
cloudWatch: {
|
||||||
|
name: 'aws',
|
||||||
|
level: "debug",
|
||||||
|
logGroupName: () => {
|
||||||
|
const hostname = os.hostname();
|
||||||
|
|
||||||
const transports = [
|
return logGroupName.replace("${instance-id}", hostname);
|
||||||
new (winston.transports.Console)(),
|
},
|
||||||
fileTransport
|
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 fileTransport = new winston.transports.DailyRotateFile(options.file);
|
||||||
|
|
||||||
|
let transports = [
|
||||||
|
new winston.transports.Console(options.console),
|
||||||
|
new winston.transports.DailyRotateFile(options.file)
|
||||||
];
|
];
|
||||||
|
|
||||||
winston.exceptions.handle(fileTransport);
|
if (aws != null && aws.accessKeyId !== '')
|
||||||
|
{
|
||||||
|
transports.push(new WinstonCloudWatch(options.cloudWatch));
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = winston.createLogger({ transports: transports, exitOnError: false });
|
//winston.exceptions.handle(fileTransport);
|
||||||
|
|
||||||
|
const customFormat = winston.format(info => {
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
info.date = date.format(now, 'YYYY-MM-DD HH:mm:ss');
|
||||||
|
info.applicationContext = "UrlShortener";
|
||||||
|
info.level = info.level.toUpperCase();
|
||||||
|
|
||||||
|
const hostname = os.hostname();
|
||||||
|
|
||||||
|
info["instance-id"] = hostname;
|
||||||
|
|
||||||
|
return info;
|
||||||
|
})();
|
||||||
|
|
||||||
|
module.exports = new winston.createLogger({
|
||||||
|
format: winston.format.combine(
|
||||||
|
customFormat,
|
||||||
|
winston.format.json()
|
||||||
|
),
|
||||||
|
transports: transports,
|
||||||
|
exitOnError: false,
|
||||||
|
});
|
@ -3,5 +3,12 @@
|
|||||||
"port": 9999,
|
"port": 9999,
|
||||||
"appsettings": "../../../config",
|
"appsettings": "../../../config",
|
||||||
"environment": "Development"
|
"environment": "Development"
|
||||||
|
},
|
||||||
|
"aws":{
|
||||||
|
"accessKeyId": "",
|
||||||
|
"secretAccessKey": "",
|
||||||
|
"region": "",
|
||||||
|
"logGroupName": "/docspace/ASC.UrlShortener/instances/${instance-id}/general",
|
||||||
|
"logStreamName": "${guid} - ${date}"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -45,4 +45,6 @@ app.use(cookieParser());
|
|||||||
app.get('/', short.make);
|
app.get('/', short.make);
|
||||||
app.get('/*', short.redirect);
|
app.get('/*', short.redirect);
|
||||||
|
|
||||||
app.listen(config.get("app").port);
|
const port = config.get("app").port;
|
||||||
|
|
||||||
|
app.listen(port, () => log.info(`Server started on port: ${port}`));
|
@ -7,14 +7,17 @@
|
|||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aws-sdk/client-cloudwatch-logs": "^3.199.0",
|
||||||
"co": "^4.6.0",
|
"co": "^4.6.0",
|
||||||
"cookie-parser": "^1.4.3",
|
"cookie-parser": "^1.4.3",
|
||||||
|
"date-and-time": "^2.4.1",
|
||||||
"express": "^4.16.3",
|
"express": "^4.16.3",
|
||||||
"moment": "^2.22.2",
|
"moment": "^2.22.2",
|
||||||
"mysql2": "^2.1.0",
|
"mysql2": "^2.1.0",
|
||||||
"nconf": "^0.10.0",
|
"nconf": "^0.10.0",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"winston": "^3.1.0",
|
"winston": "^3.8.2",
|
||||||
"winston-daily-rotate-file": "^3.3.2"
|
"winston-cloudwatch": "^6.1.1",
|
||||||
|
"winston-daily-rotate-file": "^4.5.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user