@spinajs/log 1.1.9 → 1.2.7

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.
Files changed (47) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +43 -0
  3. package/lib/config/log.js +3 -3
  4. package/lib/config/log.js.map +1 -1
  5. package/lib/decorators.d.ts +3 -3
  6. package/lib/decorators.js +4 -4
  7. package/lib/decorators.js.map +1 -1
  8. package/lib/index.d.ts +6 -2
  9. package/lib/index.js +7 -2
  10. package/lib/index.js.map +1 -1
  11. package/lib/log.d.ts +8 -32
  12. package/lib/log.js +59 -123
  13. package/lib/log.js.map +1 -1
  14. package/lib/logger.d.ts +3 -7
  15. package/lib/logger.js +14 -24
  16. package/lib/logger.js.map +1 -1
  17. package/lib/schemas/log.configuration.d.ts +1 -0
  18. package/lib/schemas/log.configuration.js +91 -97
  19. package/lib/schemas/log.configuration.js.map +1 -1
  20. package/lib/targets/BlackHoleTarget.d.ts +3 -3
  21. package/lib/targets/BlackHoleTarget.js.map +1 -1
  22. package/lib/targets/ColoredConsoleTarget.d.ts +4 -5
  23. package/lib/targets/ColoredConsoleTarget.js +18 -14
  24. package/lib/targets/ColoredConsoleTarget.js.map +1 -1
  25. package/lib/targets/FileTarget.d.ts +3 -4
  26. package/lib/targets/FileTarget.js +84 -112
  27. package/lib/targets/FileTarget.js.map +1 -1
  28. package/lib/targets/LogTarget.d.ts +10 -5
  29. package/lib/targets/LogTarget.js +38 -36
  30. package/lib/targets/LogTarget.js.map +1 -1
  31. package/lib/targets/index.d.ts +1 -0
  32. package/lib/targets/index.js +1 -0
  33. package/lib/targets/index.js.map +1 -1
  34. package/lib/types.d.ts +13 -10
  35. package/lib/types.js +8 -8
  36. package/lib/types.js.map +1 -1
  37. package/lib/variables/date.d.ts +1 -1
  38. package/lib/variables/date.js +7 -7
  39. package/lib/variables/date.js.map +1 -1
  40. package/lib/variables/env.d.ts +1 -1
  41. package/lib/variables/env.js +4 -4
  42. package/lib/variables/env.js.map +1 -1
  43. package/lib/variables/process.d.ts +2 -3
  44. package/lib/variables/process.js +4 -16
  45. package/lib/variables/process.js.map +1 -1
  46. package/package.json +14 -39
  47. package/tsconfig.build.json +9 -0
@@ -1,104 +1,102 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const CONFIGURATION_SCHEMA = {
4
- "$id": "spinajs/log.configuration.schema.json",
5
- "description": "Logger configuration option validation",
6
- "type": "object",
7
- "properties": {
8
- "targets": {
9
- "description": "Log target, where log messages should be written to, and their options",
10
- "type": "array",
11
- "minItems": 1,
12
- "uniqueItems": true,
13
- "items": {
14
- "type": "object",
15
- "properties": {
16
- "layout": {
17
- "type": "string"
4
+ $id: "spinajs/log.configuration.schema.json",
5
+ $configurationModule: "logger",
6
+ description: "Logger configuration option validation",
7
+ type: "object",
8
+ properties: {
9
+ targets: {
10
+ description: "Log target, where log messages should be written to, and their options",
11
+ type: "array",
12
+ minItems: 1,
13
+ uniqueItems: true,
14
+ items: {
15
+ type: "object",
16
+ properties: {
17
+ layout: {
18
+ type: "string",
18
19
  },
19
- "name": {
20
- "type": "string"
20
+ name: {
21
+ type: "string",
21
22
  },
22
- "type": {
23
- "type": "string"
23
+ type: {
24
+ type: "string",
24
25
  },
25
- "theme": {
26
- "type": "object",
27
- "properties": {
28
- "security": {
29
- "type": "string"
26
+ theme: {
27
+ type: "object",
28
+ properties: {
29
+ security: {
30
+ type: "string",
30
31
  },
31
- "fatal": {
32
- "type": "string"
32
+ fatal: {
33
+ type: "string",
33
34
  },
34
- "error": {
35
- "type": "string"
35
+ error: {
36
+ type: "string",
36
37
  },
37
- "warn": {
38
- "type": "string"
38
+ warn: {
39
+ type: "string",
39
40
  },
40
- "success": {
41
- "type": "string"
41
+ success: {
42
+ type: "string",
42
43
  },
43
- "info": {
44
- "type": "string"
44
+ info: {
45
+ type: "string",
45
46
  },
46
- "debug": {
47
- "type": "string"
47
+ debug: {
48
+ type: "string",
48
49
  },
49
- "trace": {
50
- "type": "string"
51
- }
52
- }
50
+ trace: {
51
+ type: "string",
52
+ },
53
+ },
54
+ },
55
+ enabled: {
56
+ type: "boolean",
53
57
  },
54
- "enabled": {
55
- "type": "boolean"
58
+ path: {
59
+ type: "string",
56
60
  },
57
- "path": {
58
- "type": "string"
61
+ archivePath: {
62
+ type: "string",
59
63
  },
60
- "archivePath": {
61
- "type": "string"
64
+ maxSize: {
65
+ type: "integer",
66
+ minimum: 10000,
62
67
  },
63
- "maxSize": {
64
- "type": "integer",
65
- "minimum": 10000
68
+ compress: {
69
+ type: "boolean",
66
70
  },
67
- "compress": {
68
- "type": "boolean"
71
+ rotate: {
72
+ type: "string",
69
73
  },
70
- "rotate": {
71
- "type": "string"
74
+ maxArchiveFiles: {
75
+ type: "integer",
76
+ minimum: 1,
72
77
  },
73
- "maxArchiveFiles": {
74
- "type": "integer",
75
- "minimum": 1
78
+ bufferSize: {
79
+ type: "integer",
80
+ minimum: 1000,
76
81
  },
77
- "bufferSize": {
78
- "type": "integer",
79
- "minimum": 1000
80
- }
81
82
  },
82
- "required": [
83
- "name",
84
- "type"
85
- ]
86
- }
83
+ required: ["name", "type"],
84
+ },
87
85
  },
88
- "rules": {
89
- "description": "Log rules, what log should be write where",
90
- "type": "array",
91
- "minItems": 1,
92
- "uniqueItems": true,
93
- "items": {
94
- "type": "object",
95
- "properties": {
96
- "name": {
97
- "type": "string"
86
+ rules: {
87
+ description: "Log rules, what log should be write where",
88
+ type: "array",
89
+ minItems: 1,
90
+ uniqueItems: true,
91
+ items: {
92
+ type: "object",
93
+ properties: {
94
+ name: {
95
+ type: "string",
98
96
  },
99
- "level": {
100
- "type": "string",
101
- "enum": [
97
+ level: {
98
+ type: "string",
99
+ enum: [
102
100
  "trace",
103
101
  "debug",
104
102
  "warn",
@@ -106,31 +104,27 @@ const CONFIGURATION_SCHEMA = {
106
104
  "error",
107
105
  "fatal",
108
106
  "security",
109
- "success"
110
- ]
107
+ "success",
108
+ ],
111
109
  },
112
- "target": {
113
- "oneOf": [
110
+ target: {
111
+ oneOf: [
114
112
  {
115
- "type": "string"
113
+ type: "string",
116
114
  },
117
115
  {
118
- "type": "array",
119
- "items": {
120
- "type": "string"
121
- }
122
- }
123
- ]
124
- }
116
+ type: "array",
117
+ items: {
118
+ type: "string",
119
+ },
120
+ },
121
+ ],
122
+ },
125
123
  },
126
- "required": [
127
- "name",
128
- "level",
129
- "target"
130
- ]
131
- }
132
- }
133
- }
124
+ required: ["name", "level", "target"],
125
+ },
126
+ },
127
+ },
134
128
  };
135
129
  exports.default = CONFIGURATION_SCHEMA;
136
130
  //# sourceMappingURL=log.configuration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"log.configuration.js","sourceRoot":"","sources":["../../src/schemas/log.configuration.ts"],"names":[],"mappings":";;AAAA,MAAM,oBAAoB,GAAG;IACzB,KAAK,EAAE,uCAAuC;IAC9C,aAAa,EAAE,wCAAwC;IACvD,MAAM,EAAE,QAAQ;IAChB,YAAY,EAAE;QACV,SAAS,EAAE;YACP,aAAa,EAAE,wEAAwE;YACvF,MAAM,EAAE,OAAO;YACf,UAAU,EAAE,CAAC;YACb,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE;gBACL,MAAM,EAAE,QAAQ;gBAChB,YAAY,EAAE;oBACV,QAAQ,EAAE;wBACN,MAAM,EAAE,QAAQ;qBACnB;oBACD,MAAM,EAAE;wBACJ,MAAM,EAAE,QAAQ;qBACnB;oBACD,MAAM,EAAE;wBACJ,MAAM,EAAE,QAAQ;qBACnB;oBACD,OAAO,EAAE;wBACL,MAAM,EAAE,QAAQ;wBAChB,YAAY,EAAE;4BACV,UAAU,EAAE;gCACR,MAAM,EAAE,QAAQ;6BACnB;4BACD,OAAO,EAAE;gCACL,MAAM,EAAE,QAAQ;6BACnB;4BACD,OAAO,EAAE;gCACL,MAAM,EAAE,QAAQ;6BACnB;4BACD,MAAM,EAAE;gCACJ,MAAM,EAAE,QAAQ;6BACnB;4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6BACnB;4BACD;gCACI,MAAM,EAAE,OAAO;gCACf,OAAO,EAAE;oCACL,MAAM,EAAE,QAAQ;iCACnB;6BACJ;yBACJ;qBACJ;iBACJ;gBACD,UAAU,EAAE;oBACR,MAAM;oBACN,OAAO;oBACP,QAAQ;iBACX;aACJ;SACJ;KACJ;CACJ,CAAA;AAED,kBAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"log.configuration.js","sourceRoot":"","sources":["../../src/schemas/log.configuration.ts"],"names":[],"mappings":";;AAAA,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,uCAAuC;IAC5C,oBAAoB,EAAE,QAAQ;IAC9B,WAAW,EAAE,wCAAwC;IACrD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,OAAO,EAAE;YACP,WAAW,EACT,wEAAwE;YAC1E,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC;YACX,WAAW,EAAE,IAAI;YACjB,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,IAAI,EAAE,QAAQ;qBACf;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE,QAAQ;qBACf;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE,QAAQ;qBACf;oBACD,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,QAAQ,EAAE;gCACR,IAAI,EAAE,QAAQ;6BACf;4BACD,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;6BACf;4BACD,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;6BACf;4BACD,IAAI,EAAE;gCACJ,IAAI,EAAE,QAAQ;6BACf;4BACD,OAAO,EAAE;gCACP,IAAI,EAAE,QAAQ;6BACf;4BACD,IAAI,EAAE;gCACJ,IAAI,EAAE,QAAQ;6BACf;4BACD,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;6BACf;4BACD,KAAK,EAAE;gCACL,IAAI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,kBAAe,oBAAoB,CAAC"}
@@ -1,8 +1,8 @@
1
- import { IBlackHoleTargetOptions } from './../types';
2
- import { LogTarget } from './LogTarget';
1
+ import { ICommonTargetOptions } from "@spinajs/log-common";
2
+ import { LogTarget } from "./LogTarget";
3
3
  /**
4
4
  * Empty writer, usefull for tests or when we dont want to get any messages
5
5
  */
6
- export declare class BlackHoleTarget extends LogTarget<IBlackHoleTargetOptions> {
6
+ export declare class BlackHoleTarget extends LogTarget<ICommonTargetOptions> {
7
7
  write(): Promise<void>;
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BlackHoleTarget.js","sourceRoot":"","sources":["../../src/targets/BlackHoleTarget.ts"],"names":[],"mappings":";;;;;;;;;AACA,oCAAoD;AACpD,2CAAwC;AAExC;;GAEG;AAGH,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,qBAAkC;IAE5D,KAAK,CAAC,KAAK;QACd,OAAO;IACX,CAAC;CAEJ,CAAA;AANY,eAAe;IAF3B,IAAA,cAAS,GAAE;IACX,IAAA,eAAU,EAAC,iBAAiB,CAAC;GACjB,eAAe,CAM3B;AANY,0CAAe"}
1
+ {"version":3,"file":"BlackHoleTarget.js","sourceRoot":"","sources":["../../src/targets/BlackHoleTarget.ts"],"names":[],"mappings":";;;;;;;;;AACA,oCAAoD;AACpD,2CAAwC;AAExC;;GAEG;AAGH,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,qBAA+B;IAC3D,KAAK,CAAC,KAAK;QAChB,OAAO;IACT,CAAC;CACF,CAAA;AAJY,eAAe;IAF3B,IAAA,cAAS,GAAE;IACX,IAAA,eAAU,EAAC,iBAAiB,CAAC;GACjB,eAAe,CAI3B;AAJY,0CAAe"}
@@ -1,6 +1,5 @@
1
- import { IColoredConsoleTargetOptions, ILogTargetData } from './../types';
2
- import { IContainer } from '@spinajs/di';
3
- import { LogTarget } from './LogTarget';
1
+ import { IColoredConsoleTargetOptions, ILogEntry } from "@spinajs/log-common";
2
+ import { LogTarget } from "./LogTarget";
4
3
  export declare const DEFAULT_THEME: {
5
4
  security: string[];
6
5
  fatal: string;
@@ -46,6 +45,6 @@ export declare class ColoredConsoleTarget extends LogTarget<IColoredConsoleTarge
46
45
  (message?: any, ...optionalParams: any[]): void;
47
46
  };
48
47
  };
49
- resolve(_: IContainer): void;
50
- write(data: ILogTargetData): Promise<void>;
48
+ resolve(): void;
49
+ write(data: ILogEntry): Promise<void>;
51
50
  }
@@ -7,21 +7,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ColoredConsoleTarget = exports.DEFAULT_THEME = void 0;
10
- const types_1 = require("./../types");
10
+ const log_common_1 = require("@spinajs/log-common");
11
11
  const di_1 = require("@spinajs/di");
12
12
  const LogTarget_1 = require("./LogTarget");
13
13
  const __1 = require("..");
14
- // tslint:disable-next-line
15
- const colors = require('colors/safe');
14
+ const colors = require("colors/safe");
16
15
  exports.DEFAULT_THEME = {
17
- security: ['red', "bgBrightWhite"],
18
- fatal: 'red',
19
- error: 'brightRed',
20
- warn: 'yellow',
21
- success: 'green',
22
- info: 'white',
23
- debug: 'gray',
24
- trace: 'gray',
16
+ security: ["red", "bgBrightWhite"],
17
+ fatal: "red",
18
+ error: "brightRed",
19
+ warn: "yellow",
20
+ success: "green",
21
+ info: "white",
22
+ debug: "gray",
23
+ trace: "gray",
25
24
  };
26
25
  let ColoredConsoleTarget = class ColoredConsoleTarget extends LogTarget_1.LogTarget {
27
26
  constructor() {
@@ -37,16 +36,21 @@ let ColoredConsoleTarget = class ColoredConsoleTarget extends LogTarget_1.LogTar
37
36
  [__1.LogLevel.Warn]: console.warn,
38
37
  };
39
38
  }
40
- resolve(_) {
39
+ resolve() {
41
40
  var _a;
42
41
  colors.setTheme((_a = this.Options.theme) !== null && _a !== void 0 ? _a : exports.DEFAULT_THEME);
43
- super.resolve(_);
42
+ super.resolve();
44
43
  }
45
44
  async write(data) {
46
45
  if (!this.Options.enabled) {
47
46
  return;
48
47
  }
49
- this.StdConsoleCallbackMap[data.Level](colors[types_1.LogLevelStrings[data.Level]](this.format(data.Variables, this.Options.layout)));
48
+ this.StdConsoleCallbackMap[data.Level](
49
+ /**
50
+ * we are safe to call, disable eslint
51
+ */
52
+ /* eslint-disable */
53
+ colors[log_common_1.LogLevelStrings[data.Level]](this.format(data.Variables, this.Options.layout)));
50
54
  }
51
55
  };
52
56
  ColoredConsoleTarget = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"ColoredConsoleTarget.js","sourceRoot":"","sources":["../../src/targets/ColoredConsoleTarget.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sCAA2F;AAC3F,oCAAgE;AAChE,2CAAwC;AACxC,0BAA8B;AAE9B,2BAA2B;AAC3B,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAEzB,QAAA,aAAa,GAAG;IACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC;IAClC,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,MAAM;CAChB,CAAA;AAID,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,qBAAuC;IAAjF;;QAEc,0BAAqB,GAAG;YAC9B,CAAC,YAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK;YAC/B,CAAC,YAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK;YAC/B,CAAC,YAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,KAAK;YAElC,CAAC,YAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,GAAG;YAC5B,CAAC,YAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG;YAE/B,CAAC,YAAQ,CAAC,KAAK,CA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U,EAAC,eAAe,CAAC;GACf,oBAAoB,CAmChC;AAnCY,oDAAoB"}
@@ -1,6 +1,5 @@
1
- import { IContainer } from "@spinajs/di";
2
1
  import { LogTarget } from "./LogTarget";
3
- import { IFileTargetOptions, ILogTargetData } from "../types";
2
+ import { IFileTargetOptions, ILogEntry } from "@spinajs/log-common";
4
3
  import { Job } from "node-schedule";
5
4
  export declare class FileTarget extends LogTarget<IFileTargetOptions> {
6
5
  protected LogDirPath: string;
@@ -15,8 +14,8 @@ export declare class FileTarget extends LogTarget<IFileTargetOptions> {
15
14
  protected CurrentFileSize: number;
16
15
  protected BufferSize: number;
17
16
  protected Buffer: any[];
18
- resolve(_: IContainer): void;
19
- write(data: ILogTargetData): Promise<void>;
17
+ resolve(): void;
18
+ write(data: ILogEntry): Promise<void>;
20
19
  protected archive(): void;
21
20
  protected flush(): void;
22
21
  private rotate;
@@ -1,68 +1,47 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
2
+ /* eslint security/detect-non-literal-fs-filename:0 -- Safe as no value holds user input */
14
3
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
15
4
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
5
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
6
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
7
  return c > 3 && r && Object.defineProperty(target, key, r), r;
19
8
  };
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
27
- var __importDefault = (this && this.__importDefault) || function (mod) {
28
- return (mod && mod.__esModule) ? mod : { "default": mod };
29
- };
30
9
  Object.defineProperty(exports, "__esModule", { value: true });
31
10
  exports.FileTarget = void 0;
32
11
  const di_1 = require("@spinajs/di");
33
12
  const LogTarget_1 = require("./LogTarget");
34
- const fs_1 = __importDefault(require("fs"));
35
- const path_1 = __importDefault(require("path"));
13
+ const fs = require("fs");
14
+ const path = require("path");
36
15
  const node_schedule_1 = require("node-schedule");
37
16
  const exceptions_1 = require("@spinajs/exceptions");
38
17
  const os_1 = require("os");
39
- const glob = __importStar(require("glob"));
40
- const zlib = __importStar(require("zlib"));
18
+ const glob = require("glob");
19
+ const zlib = require("zlib");
41
20
  let FileTarget = class FileTarget extends LogTarget_1.LogTarget {
42
21
  constructor() {
43
22
  super(...arguments);
44
23
  this.BufferSize = 0;
45
24
  this.Buffer = [];
46
25
  }
47
- resolve(_) {
26
+ resolve() {
48
27
  this.Options.options = Object.assign({
49
28
  compress: true,
50
29
  maxSize: 1024 * 1024,
51
30
  maxArchiveFiles: 5,
52
31
  bufferSize: 8 * 1024,
53
- flushTimeout: 10 * 1000
32
+ flushTimeout: 10 * 1000,
54
33
  }, this.Options.options);
55
34
  this.initialize();
56
35
  this.rotate();
57
36
  process.on("exit", () => {
58
37
  this.flush();
59
38
  if (this.LogFileDescriptor) {
60
- fs_1.default.closeSync(this.LogFileDescriptor);
39
+ fs.closeSync(this.LogFileDescriptor);
61
40
  }
62
41
  });
63
- super.resolve(_);
42
+ super.resolve();
64
43
  }
65
- async write(data) {
44
+ write(data) {
66
45
  if (!this.Options.enabled) {
67
46
  return;
68
47
  }
@@ -78,60 +57,57 @@ let FileTarget = class FileTarget extends LogTarget_1.LogTarget {
78
57
  }
79
58
  }
80
59
  archive() {
81
- const files = glob.sync(path_1.default.join(this.ArchiveDirPath, `archived_${this.LogBaseName}*{${this.LogFileExt},.gzip}`)).map(f => {
60
+ const files = glob
61
+ .sync(path.join(this.ArchiveDirPath, `archived_${this.LogBaseName}*{${this.LogFileExt},.gzip}`))
62
+ .map((f) => {
82
63
  return {
83
64
  name: f,
84
- stat: fs_1.default.statSync(f)
65
+ stat: fs.statSync(f),
85
66
  };
86
- }).sort(x => x.stat.mtime.getTime());
67
+ })
68
+ .sort((x) => x.stat.mtime.getTime());
87
69
  const newestFile = files.length !== 0 ? files[files.length - 1].name : undefined;
88
- const fIndex = newestFile ? parseInt(newestFile.substring(newestFile.lastIndexOf("_") + 1, newestFile.lastIndexOf("_") + 2), 10) + 1 : 1;
89
- const archPath = path_1.default.join(this.ArchiveDirPath, `archived_${this.LogBaseName}_${fIndex}${this.LogFileExt}`);
90
- try {
91
- this.flush();
92
- if (!fs_1.default.existsSync(this.LogPath)) {
93
- return;
94
- }
95
- fs_1.default.closeSync(this.LogFileDescriptor);
96
- fs_1.default.copyFileSync(this.LogPath, archPath);
97
- fs_1.default.unlinkSync(this.LogPath);
98
- this.initialize();
99
- if (this.Options.options.compress) {
100
- const zippedPath = path_1.default.join(this.ArchiveDirPath, `archived_${this.LogBaseName}_${fIndex}${this.LogFileExt}.gzip`);
101
- const zip = zlib.createGzip();
102
- const read = fs_1.default.createReadStream(archPath);
103
- const write = fs_1.default.createWriteStream(zippedPath);
104
- read.pipe(zip).pipe(write);
105
- write.on("finish", () => {
106
- read.close();
107
- zip.close();
108
- write.close();
109
- fs_1.default.unlink(archPath, () => { return; });
70
+ const fIndex = newestFile
71
+ ? parseInt(newestFile.substring(newestFile.lastIndexOf("_") + 1, newestFile.lastIndexOf("_") + 2), 10) + 1
72
+ : 1;
73
+ const archPath = path.join(this.ArchiveDirPath, `archived_${this.LogBaseName}_${fIndex}${this.LogFileExt}`);
74
+ this.flush();
75
+ if (!fs.existsSync(this.LogPath)) {
76
+ return;
77
+ }
78
+ fs.closeSync(this.LogFileDescriptor);
79
+ fs.copyFileSync(this.LogPath, archPath);
80
+ fs.unlinkSync(this.LogPath);
81
+ this.initialize();
82
+ if (this.Options.options.compress) {
83
+ const zippedPath = path.join(this.ArchiveDirPath, `archived_${this.LogBaseName}_${fIndex}${this.LogFileExt}.gzip`);
84
+ const zip = zlib.createGzip();
85
+ const read = fs.createReadStream(archPath);
86
+ const write = fs.createWriteStream(zippedPath);
87
+ read.pipe(zip).pipe(write);
88
+ write.on("finish", () => {
89
+ read.close();
90
+ zip.close();
91
+ write.close();
92
+ fs.unlink(archPath, () => {
93
+ return;
110
94
  });
111
- }
112
- if (files.length >= this.Options.options.maxArchiveFiles) {
113
- fs_1.default.unlink(files[0].name, () => { return; });
114
- }
95
+ });
115
96
  }
116
- catch (err) {
117
- this.Error = err;
118
- this.HasError = true;
97
+ if (files.length >= this.Options.options.maxArchiveFiles) {
98
+ fs.unlink(files[0].name, () => {
99
+ return;
100
+ });
119
101
  }
120
102
  }
121
103
  flush() {
122
104
  if (!this.LogFileDescriptor || this.HasError || this.BufferSize === 0) {
123
105
  return;
124
106
  }
125
- try {
126
- fs_1.default.writeFileSync(this.LogFileDescriptor, this.Buffer.join());
127
- this.CurrentFileSize += this.BufferSize;
128
- this.Buffer = [];
129
- this.BufferSize = 0;
130
- }
131
- catch (err) {
132
- this.HasError = true;
133
- this.Error = err;
134
- }
107
+ fs.writeFileSync(this.LogFileDescriptor, this.Buffer.join());
108
+ this.CurrentFileSize += this.BufferSize;
109
+ this.Buffer = [];
110
+ this.BufferSize = 0;
135
111
  }
136
112
  rotate() {
137
113
  if (this.Options.options.rotate) {
@@ -141,48 +117,44 @@ let FileTarget = class FileTarget extends LogTarget_1.LogTarget {
141
117
  }
142
118
  }
143
119
  initialize() {
144
- try {
145
- this.flush();
146
- if (this.LogFileDescriptor >= 0) {
147
- fs_1.default.closeSync(this.LogFileDescriptor);
148
- this.LogFileDescriptor = 0;
149
- }
150
- this.CurrentFileSize = 0;
151
- this.LogDirPath = this.format({}, path_1.default.dirname(path_1.default.resolve(this.Options.options.path)));
152
- this.ArchiveDirPath = this.Options.options.archivePath ? this.format({}, path_1.default.resolve(this.Options.options.archivePath)) : this.LogDirPath;
153
- this.LogFileName = this.format({}, path_1.default.basename(this.Options.options.path));
154
- this.LogPath = path_1.default.join(this.LogDirPath, this.LogFileName);
155
- const { name, ext } = path_1.default.parse(this.LogFileName);
156
- this.LogFileExt = ext;
157
- this.LogBaseName = name;
158
- if (!this.LogDirPath) {
159
- throw new exceptions_1.InvalidOption("Missing LogDirPath log option");
160
- }
161
- if (!fs_1.default.existsSync(this.LogDirPath)) {
162
- fs_1.default.mkdirSync(this.LogDirPath);
163
- }
164
- if (this.ArchiveDirPath) {
165
- if (!fs_1.default.existsSync(this.ArchiveDirPath)) {
166
- fs_1.default.mkdirSync(this.ArchiveDirPath);
167
- }
168
- }
169
- if (fs_1.default.existsSync(this.LogPath)) {
170
- const { size } = fs_1.default.statSync(this.LogPath);
171
- this.CurrentFileSize = size;
172
- }
173
- this.LogFileDescriptor = fs_1.default.openSync(this.LogPath, "a");
174
- if (this.Options.options.flushTimeout !== 0) {
175
- setTimeout(() => {
176
- this.flush();
177
- }, this.Options.options.flushTimeout);
120
+ this.flush();
121
+ if (this.LogFileDescriptor >= 0) {
122
+ fs.closeSync(this.LogFileDescriptor);
123
+ this.LogFileDescriptor = 0;
124
+ }
125
+ this.CurrentFileSize = 0;
126
+ this.LogDirPath = this.format(null, path.dirname(path.resolve(this.Options.options.path)));
127
+ this.ArchiveDirPath = this.Options.options.archivePath
128
+ ? this.format(null, path.resolve(this.Options.options.archivePath))
129
+ : this.LogDirPath;
130
+ this.LogFileName = this.format(null, path.basename(this.Options.options.path));
131
+ this.LogPath = path.join(this.LogDirPath, this.LogFileName);
132
+ const { name, ext } = path.parse(this.LogFileName);
133
+ this.LogFileExt = ext;
134
+ this.LogBaseName = name;
135
+ if (!this.LogDirPath) {
136
+ throw new exceptions_1.InvalidOption("Missing LogDirPath log option");
137
+ }
138
+ if (!fs.existsSync(this.LogDirPath)) {
139
+ fs.mkdirSync(this.LogDirPath);
140
+ }
141
+ if (this.ArchiveDirPath) {
142
+ if (!fs.existsSync(this.ArchiveDirPath)) {
143
+ fs.mkdirSync(this.ArchiveDirPath);
178
144
  }
179
- this.HasError = false;
180
- this.Error = null;
181
145
  }
182
- catch (err) {
183
- this.HasError = true;
184
- this.Error = err;
146
+ if (fs.existsSync(this.LogPath)) {
147
+ const { size } = fs.statSync(this.LogPath);
148
+ this.CurrentFileSize = size;
149
+ }
150
+ this.LogFileDescriptor = fs.openSync(this.LogPath, "a");
151
+ if (this.Options.options.flushTimeout !== 0) {
152
+ setTimeout(() => {
153
+ this.flush();
154
+ }, this.Options.options.flushTimeout);
185
155
  }
156
+ this.HasError = false;
157
+ this.Error = null;
186
158
  }
187
159
  };
188
160
  FileTarget = __decorate([