mas-server 2.0.56 → 2.0.57

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.
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const morgan_1 = __importDefault(require("morgan"));
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const rfs = __importStar(require("rotating-file-stream"));
32
+ const moment_timezone_1 = __importDefault(require("moment-timezone"));
32
33
  const getLogs = (app, dir) => {
33
34
  // 创建一个日志目录(如果它不存在的话)
34
35
  const logDirectory = dir;
@@ -39,6 +40,9 @@ const getLogs = (app, dir) => {
39
40
  interval: "1d",
40
41
  path: logDirectory,
41
42
  });
43
+ morgan_1.default.token("date", (req, res, tz) => {
44
+ return (0, moment_timezone_1.default)().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");
45
+ });
42
46
  app.use((0, morgan_1.default)("combined", { stream: accessLogStream }));
43
47
  };
44
48
  exports.default = getLogs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mas-server",
3
- "version": "2.0.56",
3
+ "version": "2.0.57",
4
4
  "description": "一款基于express面向中小型项目的后端框架",
5
5
  "main": "dist/index.js",
6
6
  "typings": "src/index.ts",
@@ -32,6 +32,7 @@
32
32
  "masmysql": "^2.0.53",
33
33
  "module-alias": "^2.2.2",
34
34
  "moment": "^2.29.4",
35
+ "moment-timezone": "^0.5.44",
35
36
  "morgan": "^1.10.0",
36
37
  "mysql": "^2.18.1",
37
38
  "nodemon": "^2.0.22",
package/src/utils/logs.ts CHANGED
@@ -2,6 +2,7 @@ import rateLimit from "express-rate-limit";
2
2
  import morgan from "morgan";
3
3
  import fs from "fs";
4
4
  import * as rfs from "rotating-file-stream";
5
+ import moment from "moment-timezone";
5
6
  const getLogs = (app: any, dir: string) => {
6
7
  // 创建一个日志目录(如果它不存在的话)
7
8
  const logDirectory = dir;
@@ -12,6 +13,9 @@ const getLogs = (app: any, dir: string) => {
12
13
  interval: "1d", // 每天滚动日志
13
14
  path: logDirectory,
14
15
  });
16
+ morgan.token("date", (req, res, tz) => {
17
+ return moment().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");
18
+ });
15
19
  app.use(morgan("combined", { stream: accessLogStream }));
16
20
  };
17
21
  export default getLogs;