日志:短链接记录
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { genCode } from "@pubUtils/util";
|
||||
|
||||
module.exports = () => {
|
||||
return async function log(ctx, next) {
|
||||
ctx.logcode = genCode(10);
|
||||
|
||||
ctx.service.utils.log('INFO', `[${ctx.request.url}] [${ctx.logcode}] request: ${JSON.stringify(ctx.request.body)}`)
|
||||
|
||||
|
||||
try{
|
||||
await next();
|
||||
} catch(e) {
|
||||
ctx.service.utils.log('ERROR', `[${ctx.request.url}] [${ctx.logcode}] err: ${e.stack}`);
|
||||
throw e;
|
||||
}
|
||||
const resBody = ctx.body;
|
||||
ctx.service.utils.log('INFO', `[${ctx.request.url}] [${ctx.logcode}] res: ${JSON.stringify(resBody)}`)
|
||||
};
|
||||
};
|
||||
|
||||
@@ -36,4 +36,18 @@ export default class Utils extends Service {
|
||||
public checkActivityData(data: any, type: number) {
|
||||
return { data, type }
|
||||
}
|
||||
|
||||
public log(level: 'DEBUG'|'INFO'|'WARN'| 'ERROR', message: string) {
|
||||
const log = this.app.loggers.get('linkLogger');
|
||||
|
||||
if(level == 'DEBUG') {
|
||||
log.error(`${message}`);
|
||||
} else if (level == 'INFO') {
|
||||
log.info(`${message}`);
|
||||
} else if (level == 'WARN') {
|
||||
log.warn(`${message}`);
|
||||
} else if (level == "ERROR") {
|
||||
log.error(`${message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||
const path = require('path');
|
||||
|
||||
export default (appInfo: EggAppInfo) => {
|
||||
const config = {} as PowerPartial<EggAppConfig>;
|
||||
@@ -8,7 +9,7 @@ export default (appInfo: EggAppInfo) => {
|
||||
config.keys = appInfo.name + '_1600244957952_7142';
|
||||
|
||||
// add your egg config in here
|
||||
config.middleware = [];
|
||||
config.middleware = ['log'];
|
||||
|
||||
config.cluster = {
|
||||
listen: {
|
||||
@@ -47,6 +48,22 @@ export default (appInfo: EggAppInfo) => {
|
||||
packages: [ '/root/zyz/web-server/package.json' ],
|
||||
};
|
||||
|
||||
config.customLogger = {
|
||||
linkLogger: {
|
||||
file: path.join(appInfo.root, 'logs/gm-server/link-log.log'),
|
||||
formatter(meta) {
|
||||
return `[${meta.level}] [${meta.date}] ${meta.message}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
config.logrotator = {
|
||||
filesRotateBySize: [
|
||||
path.join(appInfo.root, 'logs/link-log.log'),
|
||||
],
|
||||
maxFileSize: 1024,
|
||||
};
|
||||
|
||||
// the return config will combines to EggAppConfig
|
||||
return {
|
||||
...config,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||
const path = require('path');
|
||||
|
||||
export default (appInfo: EggAppInfo) => {
|
||||
const config = {} as PowerPartial<EggAppConfig>;
|
||||
@@ -8,7 +9,7 @@ export default (appInfo: EggAppInfo) => {
|
||||
config.keys = appInfo.name + '_1600244957952_7142';
|
||||
|
||||
// add your egg config in here
|
||||
config.middleware = [];
|
||||
config.middleware = ['log'];
|
||||
|
||||
config.cluster = {
|
||||
listen: {
|
||||
@@ -51,6 +52,22 @@ export default (appInfo: EggAppInfo) => {
|
||||
packages: [ '/root/zyz/web-server/package.json' ],
|
||||
};
|
||||
|
||||
config.customLogger = {
|
||||
linkLogger: {
|
||||
file: path.join(appInfo.root, 'logs/gm-server/link-log.log'),
|
||||
formatter(meta) {
|
||||
return `[${meta.level}] [${meta.date}] ${meta.message}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
config.logrotator = {
|
||||
filesRotateBySize: [
|
||||
path.join(appInfo.root, 'logs/link-log.log'),
|
||||
],
|
||||
maxFileSize: 1024,
|
||||
};
|
||||
|
||||
// the return config will combines to EggAppConfig
|
||||
return {
|
||||
...config,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||
const path = require('path');
|
||||
|
||||
export default (appInfo: EggAppInfo) => {
|
||||
const config = {} as PowerPartial<EggAppConfig>;
|
||||
@@ -8,7 +9,7 @@ export default (appInfo: EggAppInfo) => {
|
||||
config.keys = appInfo.name + '_1600244957952_7142';
|
||||
|
||||
// add your egg config in here
|
||||
config.middleware = [];
|
||||
config.middleware = ['log'];
|
||||
|
||||
config.cluster = {
|
||||
listen: {
|
||||
@@ -47,6 +48,22 @@ export default (appInfo: EggAppInfo) => {
|
||||
packages: [ '/root/zyz/web-server/package.json' ],
|
||||
};
|
||||
|
||||
config.customLogger = {
|
||||
linkLogger: {
|
||||
file: path.join(appInfo.root, 'logs/gm-server/link-log.log'),
|
||||
formatter(meta) {
|
||||
return `[${meta.level}] [${meta.date}] ${meta.message}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
config.logrotator = {
|
||||
filesRotateBySize: [
|
||||
path.join(appInfo.root, 'logs/link-log.log'),
|
||||
],
|
||||
maxFileSize: 1024,
|
||||
};
|
||||
|
||||
// the return config will combines to EggAppConfig
|
||||
return {
|
||||
...config,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||
const path = require('path');
|
||||
|
||||
export default (appInfo: EggAppInfo) => {
|
||||
const config = {} as PowerPartial<EggAppConfig>;
|
||||
@@ -8,7 +9,7 @@ export default (appInfo: EggAppInfo) => {
|
||||
config.keys = appInfo.name + '_1600244957952_7142';
|
||||
|
||||
// add your egg config in here
|
||||
config.middleware = [];
|
||||
config.middleware = ['log'];
|
||||
|
||||
config.cluster = {
|
||||
listen: {
|
||||
@@ -51,6 +52,22 @@ export default (appInfo: EggAppInfo) => {
|
||||
packages: [ '/root/zyz/web-server/package.json' ],
|
||||
};
|
||||
|
||||
config.customLogger = {
|
||||
linkLogger: {
|
||||
file: path.join(appInfo.root, 'logs/gm-server/link-log.log'),
|
||||
formatter(meta) {
|
||||
return `[${meta.level}] [${meta.date}] ${meta.message}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
config.logrotator = {
|
||||
filesRotateBySize: [
|
||||
path.join(appInfo.root, 'logs/link-log.log'),
|
||||
],
|
||||
maxFileSize: 1024,
|
||||
};
|
||||
|
||||
// the return config will combines to EggAppConfig
|
||||
return {
|
||||
...config,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||
const path = require('path');
|
||||
|
||||
export default (appInfo: EggAppInfo) => {
|
||||
const config = {} as PowerPartial<EggAppConfig>;
|
||||
@@ -8,7 +9,7 @@ export default (appInfo: EggAppInfo) => {
|
||||
config.keys = appInfo.name + '_1600244957952_7142';
|
||||
|
||||
// add your egg config in here
|
||||
config.middleware = [];
|
||||
config.middleware = ['log'];
|
||||
|
||||
config.cluster = {
|
||||
listen: {
|
||||
@@ -47,6 +48,22 @@ export default (appInfo: EggAppInfo) => {
|
||||
packages: [ '/root/zyz/web-server/package.json' ],
|
||||
};
|
||||
|
||||
config.customLogger = {
|
||||
linkLogger: {
|
||||
file: path.join(appInfo.root, 'logs/gm-server/link-log.log'),
|
||||
formatter(meta) {
|
||||
return `[${meta.level}] [${meta.date}] ${meta.message}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
config.logrotator = {
|
||||
filesRotateBySize: [
|
||||
path.join(appInfo.root, 'logs/link-log.log'),
|
||||
],
|
||||
maxFileSize: 1024,
|
||||
};
|
||||
|
||||
// the return config will combines to EggAppConfig
|
||||
return {
|
||||
...config,
|
||||
|
||||
+2
@@ -2,10 +2,12 @@
|
||||
// Do not modify this file!!!!!!!!!
|
||||
|
||||
import 'egg';
|
||||
import ExportLog from '../../../app/middleware/log';
|
||||
import ExportTokenParser from '../../../app/middleware/tokenParser';
|
||||
|
||||
declare module 'egg' {
|
||||
interface IMiddleware {
|
||||
log: typeof ExportLog;
|
||||
tokenParser: typeof ExportTokenParser;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user