@nocobase/plugin-logger 1.0.0-alpha.9 → 1.0.1-alpha.2
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.
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
(function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react-i18next"),require("react/jsx-runtime"),require("react"),require("antd"),require("@ant-design/icons"),require("ahooks")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react-i18next","react/jsx-runtime","react","antd","@ant-design/icons","ahooks"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@nocobase/plugin-logger"]={},e["@nocobase/client"],e["react-i18next"],e.jsxRuntime,e.react,e.antd,e["@ant-design/icons"],e.ahooks))})(this,function(e,t,s,r,a,d,k,y){"use strict";var Y=Object.defineProperty,Z=Object.defineProperties;var R=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var V=(e,t,s)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,A=(e,t)=>{for(var s in t||(t={}))ee.call(t,s)&&V(e,s,t[s]);if($)for(var s of $(t))te.call(t,s)&&V(e,s,t[s]);return e},C=(e,t)=>Z(e,R(t));var S=(e,t,s)=>new Promise((r,a)=>{var d=
|
|
10
|
+
(function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react-i18next"),require("react/jsx-runtime"),require("react"),require("antd"),require("@ant-design/icons"),require("ahooks")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react-i18next","react/jsx-runtime","react","antd","@ant-design/icons","ahooks"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@nocobase/plugin-logger"]={},e["@nocobase/client"],e["react-i18next"],e.jsxRuntime,e.react,e.antd,e["@ant-design/icons"],e.ahooks))})(this,function(e,t,s,r,a,d,k,y){"use strict";var Y=Object.defineProperty,Z=Object.defineProperties;var R=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var V=(e,t,s)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,A=(e,t)=>{for(var s in t||(t={}))ee.call(t,s)&&V(e,s,t[s]);if($)for(var s of $(t))te.call(t,s)&&V(e,s,t[s]);return e},C=(e,t)=>Z(e,R(t));var S=(e,t,s)=>new Promise((r,a)=>{var d=p=>{try{y(s.next(p))}catch(f){a(f)}},k=p=>{try{y(s.throw(p))}catch(f){a(f)}},y=p=>p.done?r(p.value):Promise.resolve(p.value).then(d,k);y((s=s.apply(e,t)).next())});const p="logger";function f(g){return t.i18n.t(g,{ns:p})}function L(){return s.useTranslation(p)}const{Paragraph:E,Text:b}=d.Typography,M=a.memo(()=>{const{t:g}=L();return r.jsxs(d.Typography,{children:[r.jsxs(E,{children:[r.jsx(b,{code:!0,children:"request_*.log"})," - ",g("API request and response logs")]}),r.jsxs(E,{children:[r.jsx(b,{code:!0,children:"system_*.log"})," -"," ",g("Application, database, plugins and other system logs, the error level logs will be sent to")," ",r.jsx(b,{code:!0,children:"system_error_*.log"})]}),r.jsxs(E,{children:[r.jsx(b,{code:!0,children:"sql_*.log"})," - ",g("SQL execution logs, printed by Sequelize when the db logging is enabled")]})]})});M.displayName="Tips";const _=a.memo(g=>{const{token:P}=d.theme.useToken(),{t:H}=L(),T=y.useMemoizedFn(H),v=t.useAPIClient(),[U,I]=a.useState(["0"]),[x,G]=a.useState(""),[Q,D]=a.useState(!0),[O,z]=a.useState([]),{data:K}=t.useRequest(()=>v.resource("logger").list().then(o=>{var u;return(u=o.data)==null?void 0:u.data})),q=a.useCallback((o,u)=>o.map((i,c)=>{const n=`${u}-${c}`;return typeof i=="string"?{title:i,key:n,icon:r.jsx(k.FileOutlined,{})}:{title:i.name,key:n,icon:r.jsx(k.FolderOutlined,{}),children:q(i.files,n)}}),[]),m=a.useMemo(()=>{const o=K||[];return[{title:T("All"),key:"0",children:q(o,"0")}]},[K,q,T]),J=o=>{I(o),D(!1)},W=o=>{const{value:u}=o.target,i=n=>n.reduce((l,h)=>{var w;return(w=h.title)!=null&&w.includes(u)&&l.push(h),h.children?[...l,...i(h.children)]:l},[]),c=i(m).map(n=>n.key);I(c),G(u),D(!0),z([])},B=a.useMemo(()=>{if(!x)return m;const o=u=>{const i=[];for(const c of u){const n=c.title,l=n.indexOf(x),h=n.substring(0,l),w=n.substring(l+x.length),F=l>-1?r.jsxs("span",{children:[h,r.jsx("span",{style:{color:P.colorPrimary},children:x}),w]}):r.jsx("span",{children:n});if(l>-1)i.push(C(A({},c),{title:F}));else if(c.children){const N=o(c.children);N.length&&i.push(C(A({},c),{title:F,children:N}))}}return i};return o(m)},[x,m,P.colorPrimary]),X=()=>{const o=(i,c)=>i.reduce((n,l)=>{let h=l.title;return h=l.key==="0"?h:`${c}/${h}`,l.children?[...n,...o(l.children,l.key==="0"?"":h)]:(O.includes(l.key)&&l.key!=="0"&&n.push(h),n)},[]),u=o(m,"");u.length&&v.request({url:"logger:download",method:"post",responseType:"blob",data:{files:u}}).then(i=>{const c=window.URL.createObjectURL(new Blob([i.data],{type:"application/gzip"})),n=document.createElement("a");n.setAttribute("href",c),n.setAttribute("download","logs.tar.gz"),n.click(),n.remove()}).catch(i=>{console.log(i)})};return r.jsxs(d.Card,{style:{minHeight:"700px"},children:[r.jsx(d.Alert,{message:"",description:r.jsx(M,{}),type:"info",showIcon:!0}),r.jsx(d.Input.Search,{style:{marginTop:16,width:"450px"},placeholder:T("Search"),onChange:W}),r.jsx("div",{style:{maxHeight:"400px",width:"450px",overflow:"auto",border:"1px solid",marginTop:"6px",marginBottom:"10px",borderColor:P.colorBorder},children:B.length?r.jsx(d.Tree,{checkable:!0,showIcon:!0,showLine:!0,checkedKeys:O,expandedKeys:U,autoExpandParent:Q,onExpand:J,onCheck:o=>z(o),treeData:B}):r.jsx(d.Empty,{image:d.Empty.PRESENTED_IMAGE_SIMPLE})}),r.jsxs(d.Button,{type:"primary",onClick:X,children:[T("Download")," (.tar.gz)"]})]})});_.displayName="LogsDownloader";class j extends t.Plugin{afterAdd(){return S(this,null,function*(){})}beforeLoad(){return S(this,null,function*(){})}load(){return S(this,null,function*(){this.app.pluginSettingsManager.add("logger",{title:f("Logger"),icon:"FileTextOutlined",Component:_})})}}e.PluginLoggerClient=j,e.default=j,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.0.
|
|
11
|
+
"@nocobase/client": "1.0.1-alpha.2",
|
|
12
12
|
"react": "18.2.0",
|
|
13
13
|
"antd": "5.12.8",
|
|
14
14
|
"@ant-design/icons": "5.2.6",
|
|
15
15
|
"ahooks": "3.7.8",
|
|
16
|
-
"@nocobase/server": "1.0.
|
|
16
|
+
"@nocobase/server": "1.0.1-alpha.2",
|
|
17
17
|
"react-i18next": "11.18.6",
|
|
18
|
-
"@nocobase/actions": "1.0.
|
|
19
|
-
"@nocobase/logger": "1.0.
|
|
18
|
+
"@nocobase/actions": "1.0.1-alpha.2",
|
|
19
|
+
"@nocobase/logger": "1.0.1-alpha.2",
|
|
20
|
+
"lodash": "4.17.21"
|
|
20
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"tar-fs","version":"3.0.4","description":"filesystem bindings for tar-stream","dependencies":{"mkdirp-classic":"^0.5.2","pump":"^3.0.0","tar-stream":"^3.1.5"},"files":["index.js"],"standard":{"ignore":["test/fixtures/**"]},"keywords":["tar","fs","file","tarball","directory","stream"],"devDependencies":{"brittle":"^3.1.3","rimraf":"^2.6.3","standard":"^17.0.1"},"scripts":{"test":"standard && brittle test/index.js"},"bugs":{"url":"https://github.com/mafintosh/tar-fs/issues"},"homepage":"https://github.com/mafintosh/tar-fs","main":"index.js","directories":{"test":"test"},"author":"Mathias Buus","license":"MIT","repository":{"type":"git","url":"https://github.com/mafintosh/tar-fs.git"},"_lastModified":"2024-
|
|
1
|
+
{"name":"tar-fs","version":"3.0.4","description":"filesystem bindings for tar-stream","dependencies":{"mkdirp-classic":"^0.5.2","pump":"^3.0.0","tar-stream":"^3.1.5"},"files":["index.js"],"standard":{"ignore":["test/fixtures/**"]},"keywords":["tar","fs","file","tarball","directory","stream"],"devDependencies":{"brittle":"^3.1.3","rimraf":"^2.6.3","standard":"^17.0.1"},"scripts":{"test":"standard && brittle test/index.js"},"bugs":{"url":"https://github.com/mafintosh/tar-fs/issues"},"homepage":"https://github.com/mafintosh/tar-fs","main":"index.js","directories":{"test":"test"},"author":"Mathias Buus","license":"MIT","repository":{"type":"git","url":"https://github.com/mafintosh/tar-fs.git"},"_lastModified":"2024-06-11T12:23:53.015Z"}
|
|
@@ -45,11 +45,46 @@ var import_path = require("path");
|
|
|
45
45
|
var import_stream = __toESM(require("stream"));
|
|
46
46
|
var import_tar_fs = require("tar-fs");
|
|
47
47
|
var import_zlib = __toESM(require("zlib"));
|
|
48
|
-
|
|
48
|
+
var import_lodash = __toESM(require("lodash"));
|
|
49
|
+
const envVars = [
|
|
50
|
+
"APP_ENV",
|
|
51
|
+
"APP_PORT",
|
|
52
|
+
"API_BASE_PATH",
|
|
53
|
+
"API_BASE_URL",
|
|
54
|
+
"DB_DIALECT",
|
|
55
|
+
"DB_TABLE_PREFIX",
|
|
56
|
+
"DB_UNDERSCORED",
|
|
57
|
+
"DB_TIMEZONE",
|
|
58
|
+
"DB_LOGGING",
|
|
59
|
+
"LOGGER_TRANSPORT",
|
|
60
|
+
"LOGGER_LEVEL"
|
|
61
|
+
];
|
|
62
|
+
const getLastestLogs = async (path) => {
|
|
63
|
+
const files = await (0, import_promises.readdir)(path);
|
|
64
|
+
const prefixes = ["request", "sql", "system", "system_error"];
|
|
65
|
+
const logs = files.filter((file) => file.endsWith(".log") && prefixes.some((prefix) => file.startsWith(prefix)));
|
|
66
|
+
if (!logs.length) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const mtime = async (file) => {
|
|
70
|
+
const info = await (0, import_promises.stat)((0, import_path.join)(path, file));
|
|
71
|
+
return [file, info.mtime];
|
|
72
|
+
};
|
|
73
|
+
const logsWithTime = await Promise.all(logs.map(mtime));
|
|
74
|
+
const getLatestLog = (prefix) => {
|
|
75
|
+
const logs2 = logsWithTime.filter((file) => file[0].startsWith(prefix));
|
|
76
|
+
if (!logs2.length) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return logs2.reduce((a, b) => a[1] > b[1] ? a : b)[0];
|
|
80
|
+
};
|
|
81
|
+
return prefixes.map(getLatestLog).filter((file) => file);
|
|
82
|
+
};
|
|
83
|
+
const tarFiles = (path, files) => {
|
|
49
84
|
return new Promise((resolve, reject) => {
|
|
50
85
|
const passthrough = new import_stream.default.PassThrough();
|
|
51
86
|
const gz = import_zlib.default.createGzip();
|
|
52
|
-
(0, import_tar_fs.pack)(
|
|
87
|
+
(0, import_tar_fs.pack)(path, {
|
|
53
88
|
entries: files
|
|
54
89
|
}).on("data", (chunk) => {
|
|
55
90
|
passthrough.write(chunk);
|
|
@@ -69,7 +104,7 @@ var logger_default = {
|
|
|
69
104
|
name: "logger",
|
|
70
105
|
actions: {
|
|
71
106
|
list: async (ctx, next) => {
|
|
72
|
-
const path = (0, import_logger.getLoggerFilePath)();
|
|
107
|
+
const path = (0, import_logger.getLoggerFilePath)(ctx.app.name || "main");
|
|
73
108
|
const readDir = async (path2) => {
|
|
74
109
|
const fileTree = [];
|
|
75
110
|
try {
|
|
@@ -99,6 +134,7 @@ var logger_default = {
|
|
|
99
134
|
await next();
|
|
100
135
|
},
|
|
101
136
|
download: async (ctx, next) => {
|
|
137
|
+
const path = (0, import_logger.getLoggerFilePath)(ctx.app.name || "main");
|
|
102
138
|
let { files = [] } = ctx.action.params.values || {};
|
|
103
139
|
const invalid = files.some((file) => !file.endsWith(".log"));
|
|
104
140
|
if (invalid) {
|
|
@@ -112,7 +148,30 @@ var logger_default = {
|
|
|
112
148
|
});
|
|
113
149
|
try {
|
|
114
150
|
ctx.attachment("logs.tar.gz");
|
|
115
|
-
ctx.body = await tarFiles(files);
|
|
151
|
+
ctx.body = await tarFiles(path, files);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
ctx.log.error(`download error: ${err.message}`, { files, err: err.stack });
|
|
154
|
+
ctx.throw(500, ctx.t("Download logs failed."));
|
|
155
|
+
}
|
|
156
|
+
await next();
|
|
157
|
+
},
|
|
158
|
+
collect: async (ctx, next) => {
|
|
159
|
+
const { error, ...info } = ctx.action.params.values || {};
|
|
160
|
+
const { message, ...e } = error || {};
|
|
161
|
+
ctx.log.error({ message: `Diagnosis, frontend error, ${message}`, ...e });
|
|
162
|
+
ctx.log.error(`Diagnostic information`, info);
|
|
163
|
+
ctx.log.error("Diagnosis, environment variables", import_lodash.default.pick(process.env, envVars));
|
|
164
|
+
const path = (0, import_logger.getLoggerFilePath)(ctx.app.name || "main");
|
|
165
|
+
const files = await getLastestLogs(path);
|
|
166
|
+
if (!files.length) {
|
|
167
|
+
ctx.throw(
|
|
168
|
+
404,
|
|
169
|
+
ctx.t("No log files found. Please check the LOGGER_TRANSPORTS environment variable configuration.")
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
ctx.attachment("logs.tar.gz");
|
|
174
|
+
ctx.body = await tarFiles(path, files);
|
|
116
175
|
} catch (err) {
|
|
117
176
|
ctx.log.error(`download error: ${err.message}`, { files, err: err.stack });
|
|
118
177
|
ctx.throw(500, ctx.t("Download logs failed."));
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "日志",
|
|
5
5
|
"description": "Server-side logs, mainly including API request logs and system runtime logs, and allows to package and download log files.",
|
|
6
6
|
"description.zh-CN": "服务端日志,主要包括接口请求日志和系统运行日志,并支持打包和下载日志文件。",
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.1-alpha.2",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/logger",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@nocobase/server": "1.x",
|
|
20
20
|
"@nocobase/test": "1.x"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "fc5a8e3c812516f787cb22d3d198f058f45b1963",
|
|
23
23
|
"keywords": [
|
|
24
24
|
"Logging and monitoring"
|
|
25
25
|
]
|