diff --git a/package-lock.json b/package-lock.json index a8be91d..76462da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pwwa", - "version": "1.1.2", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pwwa", - "version": "1.1.2", + "version": "1.2.0", "dependencies": { "@auth/prisma-adapter": "^1.4.0", "@emotion/react": "^11.11.3", @@ -85,7 +85,8 @@ "uuid": "^9.0.1", "web-push": "^3.6.7", "webpack-bundle-analyzer": "^4.10.1", - "winston": "^3.11.0", + "winston": "^3.13.0", + "winston-daily-rotate-file": "^5.0.0", "xlsx": "https://cdn.sheetjs.com/xlsx-0.19.1/xlsx-0.19.1.tgz", "xlsx-style": "^0.8.13", "xml-js": "^1.6.11", @@ -7624,6 +7625,14 @@ "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==" }, + "node_modules/file-stream-rotator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/file-stream-rotator/-/file-stream-rotator-0.6.1.tgz", + "integrity": "sha512-u+dBid4PvZw17PmDeRcNOtCP9CCK/9lRN2w+r1xIS7yOL9JFrIBKTvrYsxT4P0pGtThYTn++QS5ChHaUov3+zQ==", + "dependencies": { + "moment": "^2.29.1" + } + }, "node_modules/file-type": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", @@ -17763,9 +17772,9 @@ } }, "node_modules/winston": { - "version": "3.11.0", - "resolved": "https://registry.npmjs.org/winston/-/winston-3.11.0.tgz", - "integrity": "sha512-L3yR6/MzZAOl0DsysUXHVjOwv8mKZ71TrA/41EIduGpOOV5LQVodqN+QdQ6BS6PJ/RdIshZhq84P/fStEZkk7g==", + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.13.0.tgz", + "integrity": "sha512-rwidmA1w3SE4j0E5MuIufFhyJPBDG7Nu71RkZor1p2+qHvJSZ9GYDA81AyleQcZbh/+V6HjeBdfnTZJm9rSeQQ==", "dependencies": { "@colors/colors": "^1.6.0", "@dabh/diagnostics": "^2.0.2", @@ -17777,12 +17786,37 @@ "safe-stable-stringify": "^2.3.1", "stack-trace": "0.0.x", "triple-beam": "^1.3.0", - "winston-transport": "^4.5.0" + "winston-transport": "^4.7.0" }, "engines": { "node": ">= 12.0.0" } }, + "node_modules/winston-daily-rotate-file": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/winston-daily-rotate-file/-/winston-daily-rotate-file-5.0.0.tgz", + "integrity": "sha512-JDjiXXkM5qvwY06733vf09I2wnMXpZEhxEVOSPenZMii+g7pcDcTBt2MRugnoi8BwVSuCT2jfRXBUy+n1Zz/Yw==", + "dependencies": { + "file-stream-rotator": "^0.6.1", + "object-hash": "^3.0.0", + "triple-beam": "^1.4.1", + "winston-transport": "^4.7.0" + }, + "engines": { + "node": ">=8" + }, + "peerDependencies": { + "winston": "^3" + } + }, + "node_modules/winston-daily-rotate-file/node_modules/object-hash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz", + "integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==", + "engines": { + "node": ">= 6" + } + }, "node_modules/winston-transport": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.7.0.tgz", diff --git a/package.json b/package.json index a9e5e94..9c3aef2 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,8 @@ "uuid": "^9.0.1", "web-push": "^3.6.7", "webpack-bundle-analyzer": "^4.10.1", - "winston": "^3.11.0", + "winston": "^3.13.0", + "winston-daily-rotate-file": "^5.0.0", "xlsx": "https://cdn.sheetjs.com/xlsx-0.19.1/xlsx-0.19.1.tgz", "xlsx-style": "^0.8.13", "xml-js": "^1.6.11", @@ -113,4 +114,4 @@ "depcheck": "^1.4.7", "prisma": "^5.12.1" } -} \ No newline at end of file +} diff --git a/pages/api/data/[...nextcrud].ts b/pages/api/data/[...nextcrud].ts index af64fa7..c054391 100644 --- a/pages/api/data/[...nextcrud].ts +++ b/pages/api/data/[...nextcrud].ts @@ -8,6 +8,8 @@ import { authOptions } from "../auth/[...nextauth]"; const common = require("../../../src/helpers/common"); import jwt from 'jsonwebtoken'; import { decode } from 'next-auth/jwt'; +const logger = require('../../../src/logger'); + // import { getToken } from "next-auth/jwt"; const handler = async (req: NextApiRequest, res: NextApiResponse) => { @@ -25,6 +27,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { const authHeader = req.headers.authorization || ''; //console.log('authHeader', authHeader); if (session) { + //get target table + const targetTable = req.query.nextcrud[0]; + //get target action + if (req.method === 'DELETE') { + + const targetId = req.query.nextcrud[1]; + logger.info('[nextCrud] ' + targetTable + ': ' + targetId + 'DELETED by ' + session.user.email); + } return nextCrudHandler(req, res); } else { diff --git a/src/logger.js b/src/logger.js new file mode 100644 index 0000000..eff500b --- /dev/null +++ b/src/logger.js @@ -0,0 +1,25 @@ +const winston = require('winston'); +require('winston-daily-rotate-file'); + +const logConfiguration = { + 'transports': [ + new winston.transports.DailyRotateFile({ + filename: './logs/application-%DATE%.log', + datePattern: 'YYYY-MM-DD-HH', + zippedArchive: true, + maxSize: '20m', + maxFiles: '90d', + level: 'info' + }) + ], + format: winston.format.combine( + winston.format.timestamp({ + format: 'YYYY-MM-DD HH:mm:ss' + }), + winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`) + ) +}; + +const logger = winston.createLogger(logConfiguration); + +module.exports = logger;