@steedos/service-object-mixin 2.7.0-beta.1 → 2.7.0-beta.10

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/README.md CHANGED
@@ -16,6 +16,33 @@
16
16
 
17
17
  ```
18
18
 
19
+ 为微服务提供 Methods
20
+
21
+ ### `getLogger`
22
+
23
+ 参数: json, 选填. 默认key,space: 默认值为primarySpaceId.
24
+
25
+ 返回值:
26
+ ```
27
+ {
28
+ debug: async (message, data?)=>{},
29
+ info: async (message, data?)=>{},
30
+ warn: async (message, data?)=>{},
31
+ error: async(message, data?)=>{}
32
+ }
33
+ ```
34
+
35
+ 例如
36
+ ```
37
+ actions: {
38
+ importData: function(){
39
+ const logger = await this.getLogger();
40
+ logger.debug('import data start...');
41
+
42
+ ...
43
+ }
44
+ }
45
+ ```
19
46
  ### Why should this be worked on? 此需求的应用场景?
20
47
 
21
48
  解决在微服务中用简化语法调用 objectql 的问题。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-object-mixin",
3
- "version": "2.7.0-beta.1",
3
+ "version": "2.7.0-beta.10",
4
4
  "main": "package.service.js",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -13,5 +13,5 @@
13
13
  "description": "steedos package",
14
14
  "repository": {},
15
15
  "license": "MIT",
16
- "gitHead": "529efb7f06c4454d4351500c6e47bd7b7602f64d"
16
+ "gitHead": "78659952139c455e4fdd3d581c0d242219e033d0"
17
17
  }
@@ -1,13 +1,13 @@
1
1
  /*
2
2
  * @Author: sunhaolin@hotoa.com
3
3
  * @Date: 2023-03-23 15:12:14
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-11-14 10:27:19
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2024-03-12 10:24:48
6
6
  * @Description:
7
7
  */
8
8
  "use strict";
9
9
  // @ts-check
10
-
10
+ const _ = require('lodash')
11
11
 
12
12
  /**
13
13
  * @typedef {import('moleculer').Context} Context Moleculer's Context
@@ -407,8 +407,59 @@ module.exports = {
407
407
  async handler() {
408
408
  return await this.broker.call("objectql.makeNewID")
409
409
  }
410
+ },
411
+ getLogger: {
412
+ handler: async function (meta = {}) {
413
+ if(!meta.space){
414
+ if(!this.primarySpaceId){
415
+ this.primarySpaceId = await this.broker.call("objectql.getPrimarySpaceId");
416
+ }
417
+ meta.space = this.primarySpaceId;
418
+ }
419
+ return {
420
+ debug: async (message, data)=>{
421
+ return await this.getObject('logs').directInsert({
422
+ 'level': 'debug',
423
+ 'name': message,
424
+ 'data': _.isString(data) ? data : JSON.stringify(data),
425
+ 'node_id': this.broker.nodeID,
426
+ 'created': new Date(),
427
+ ...meta
428
+ })
429
+ },
430
+ info: async (message, data)=>{
431
+ return await this.getObject('logs').directInsert({
432
+ 'level': 'info',
433
+ 'name': message,
434
+ 'data': _.isString(data) ? data : JSON.stringify(data),
435
+ 'node_id': this.broker.nodeID,
436
+ 'created': new Date(),
437
+ ...meta
438
+ })
439
+ },
440
+ warn: async (message, data)=>{
441
+ return await this.getObject('logs').directInsert({
442
+ 'level': 'warn',
443
+ 'name': message,
444
+ 'data': _.isString(data) ? data : JSON.stringify(data),
445
+ 'node_id': this.broker.nodeID,
446
+ 'created': new Date(),
447
+ ...meta
448
+ })
449
+ },
450
+ error: async (message, data)=>{
451
+ return await this.getObject('logs').directInsert({
452
+ 'level': 'error',
453
+ 'name': message,
454
+ 'data': _.isString(data) ? data : JSON.stringify(data),
455
+ 'node_id': this.broker.nodeID,
456
+ 'created': new Date(),
457
+ ...meta
458
+ })
459
+ }
460
+ }
461
+ }
410
462
  }
411
-
412
463
  },
413
464
 
414
465
  /**