@nocobase/plugin-logger 1.0.0-alpha.12 → 1.0.0-alpha.14

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.
@@ -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=h=>{try{y(s.next(h))}catch(f){a(f)}},k=h=>{try{y(s.throw(h))}catch(f){a(f)}},y=h=>h.done?r(h.value):Promise.resolve(h.value).then(d,k);y((s=s.apply(e,t)).next())});const h="logger";function f(g){return t.i18n.t(g,{ns:h})}function L(){return s.useTranslation(h)}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:"[app]/request_*.log"})," - ",g("API request and response logs")]}),r.jsxs(E,{children:[r.jsx(b,{code:!0,children:"[app]/system_*.log"})," -"," ",g("Application, database, plugins and other system logs, the error level logs will be sent to")," ",r.jsx(b,{code:!0,children:"[app]/system_error_*.log"})]}),r.jsxs(E,{children:[r.jsx(b,{code:!0,children:"[app]/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,p)=>{var w;return(w=p.title)!=null&&w.includes(u)&&l.push(p),p.children?[...l,...i(p.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),p=n.substring(0,l),w=n.substring(l+x.length),F=l>-1?r.jsxs("span",{children:[p,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 p=l.title;return p=l.key==="0"?p:`${c}/${p}`,l.children?[...n,...o(l.children,l.key==="0"?"":p)]:(O.includes(l.key)&&l.key!=="0"&&n.push(p),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"}})});
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"}})});
@@ -8,13 +8,13 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.0.0-alpha.12",
11
+ "@nocobase/client": "1.0.0-alpha.14",
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.0-alpha.12",
16
+ "@nocobase/server": "1.0.0-alpha.14",
17
17
  "react-i18next": "11.18.6",
18
- "@nocobase/actions": "1.0.0-alpha.12",
19
- "@nocobase/logger": "1.0.0-alpha.12"
18
+ "@nocobase/actions": "1.0.0-alpha.14",
19
+ "@nocobase/logger": "1.0.0-alpha.14"
20
20
  };
@@ -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-05-13T00:52:56.188Z"}
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-05-16T14:01:57.254Z"}
@@ -45,11 +45,11 @@ 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
- const tarFiles = (files) => {
48
+ const tarFiles = (path, files) => {
49
49
  return new Promise((resolve, reject) => {
50
50
  const passthrough = new import_stream.default.PassThrough();
51
51
  const gz = import_zlib.default.createGzip();
52
- (0, import_tar_fs.pack)((0, import_logger.getLoggerFilePath)(), {
52
+ (0, import_tar_fs.pack)(path, {
53
53
  entries: files
54
54
  }).on("data", (chunk) => {
55
55
  passthrough.write(chunk);
@@ -69,7 +69,7 @@ var logger_default = {
69
69
  name: "logger",
70
70
  actions: {
71
71
  list: async (ctx, next) => {
72
- const path = (0, import_logger.getLoggerFilePath)();
72
+ const path = (0, import_logger.getLoggerFilePath)(ctx.app.name || "main");
73
73
  const readDir = async (path2) => {
74
74
  const fileTree = [];
75
75
  try {
@@ -99,6 +99,7 @@ var logger_default = {
99
99
  await next();
100
100
  },
101
101
  download: async (ctx, next) => {
102
+ const path = (0, import_logger.getLoggerFilePath)(ctx.app.name || "main");
102
103
  let { files = [] } = ctx.action.params.values || {};
103
104
  const invalid = files.some((file) => !file.endsWith(".log"));
104
105
  if (invalid) {
@@ -112,7 +113,7 @@ var logger_default = {
112
113
  });
113
114
  try {
114
115
  ctx.attachment("logs.tar.gz");
115
- ctx.body = await tarFiles(files);
116
+ ctx.body = await tarFiles(path, files);
116
117
  } catch (err) {
117
118
  ctx.log.error(`download error: ${err.message}`, { files, err: err.stack });
118
119
  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.0-alpha.12",
7
+ "version": "1.0.0-alpha.14",
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": "d8db7d708cf8e7819003dbbe636238164bc5ec5b",
22
+ "gitHead": "829078819e5b9720a4c2501c340a301315c0d029",
23
23
  "keywords": [
24
24
  "Logging and monitoring"
25
25
  ]