ac-logger 2.3.1 → 3.0.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,40 @@
1
+ <a name="3.0.0"></a>
2
+
3
+ # [3.0.0](https://github.com/admiralcloud/ac-logger/compare/v2.3.2..v3.0.0) (2024-08-09 15:08:00)
4
+
5
+
6
+ ### Bug Fix
7
+
8
+ * **App:** Add colorization based on statusCode | MP | [e7d87144520ae667dce9e25b0a8c672dadacddc8](https://github.com/admiralcloud/ac-logger/commit/e7d87144520ae667dce9e25b0a8c672dadacddc8)
9
+ Add colorization based on statusCode
10
+ Related issues: [undefined/undefined#master](undefined/browse/master)
11
+ ### Style
12
+
13
+ * **App:** Lint fix | MP | [4c4c1edaecd3f94acf688fabdd78687212a12b31](https://github.com/admiralcloud/ac-logger/commit/4c4c1edaecd3f94acf688fabdd78687212a12b31)
14
+ Lint fix
15
+ Related issues: [undefined/undefined#master](undefined/browse/master)
16
+ ### Chores
17
+
18
+ * **App:** Updated packages | MP | [a2b6d3244a9db6cdd2af978fc15a0d5cfec4408d](https://github.com/admiralcloud/ac-logger/commit/a2b6d3244a9db6cdd2af978fc15a0d5cfec4408d)
19
+ Updated packages
20
+ Related issues: [undefined/undefined#master](undefined/browse/master)
21
+ ## BREAKING CHANGES
22
+ * **App:** Minimum Node version 18
23
+ <a name="2.3.2"></a>
24
+
25
+ ## [2.3.2](https://github.com/admiralcloud/ac-logger/compare/v2.3.1..v2.3.2) (2024-05-08 15:32:14)
26
+
27
+
28
+ ### Bug Fix
29
+
30
+ * **App:** Added option to change logLevel during runtime | MP | [1e59bed4b7d56dff95584fdf528f4dd931e3e6a2](https://github.com/admiralcloud/ac-logger/commit/1e59bed4b7d56dff95584fdf528f4dd931e3e6a2)
31
+ It is now possible to change loglevel after init
32
+ Related issues: [undefined/undefined#master](undefined/browse/master)
33
+ ### Chores
34
+
35
+ * **App:** Updated packages | MP | [af832d3e7cb148e625b0bcd0756d69044bcb812d](https://github.com/admiralcloud/ac-logger/commit/af832d3e7cb148e625b0bcd0756d69044bcb812d)
36
+ Updated packages
37
+ Related issues: [undefined/undefined#master](undefined/browse/master)
1
38
  <a name="2.3.1"></a>
2
39
 
3
40
  ## [2.3.1](https://github.com/admiralcloud/ac-logger/compare/v2.3.0..v2.3.1) (2024-03-10 12:31:44)
@@ -0,0 +1,32 @@
1
+ const globals = require('globals')
2
+
3
+ module.exports = {
4
+ ignores: [
5
+ 'config/env/**'
6
+ ],
7
+ languageOptions: {
8
+ ecmaVersion: 2022,
9
+ sourceType: 'module',
10
+ globals: {
11
+ ...globals.commonjs,
12
+ ...globals.es2015,
13
+ ...globals.node,
14
+ expect: 'readonly',
15
+ describe: 'readonly',
16
+ it: 'readonly'
17
+ }
18
+ },
19
+ rules: {
20
+ 'no-const-assign': 'error', // Ensure this rule is enabled
21
+ 'space-before-function-paren': 'off',
22
+ 'no-extra-semi': 'off',
23
+ 'object-curly-spacing': ['error', 'always'],
24
+ 'brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
25
+ 'no-useless-escape': 'off',
26
+ 'standard/no-callback-literal': 'off',
27
+ 'new-cap': 'off',
28
+ 'no-console': ['warn', { allow: ['warn', 'error'] }],
29
+ "no-unused-vars": "error", // we shouldn't clutter code with unused variables
30
+ "prefer-const": ["warn", { "ignoreReadBeforeAssign": true }],
31
+ }
32
+ }
package/index.js CHANGED
@@ -26,10 +26,26 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
26
26
  // http log format
27
27
  if (level === 'http' && data?.controller) {
28
28
  // display accessKey, link (if applicable)
29
- let message = data?.message ? ` ${data.message}` : ''
29
+ const message = data?.message ? ` ${data.message}` : ''
30
30
  let cuid = data?.customerId ? data?.customerId : ''
31
31
  if (data?.userId) cuid += `/${data.userId} `
32
- return `${data?.timestamp} ${data?.level} ${data?.ip} ${data?.iso2 || ''} ${data?.accessKey || ''} ${cuid}${data?.controller} ${data?.action}${message} | ${data?.statusCode} | ${data?.performance?.executionTime}ms`
32
+ // colorize status codes
33
+
34
+ const statusCode = data?.statusCode
35
+ let displayStatusCode = (statusCode || ' ')
36
+ if (statusCode >= 500) {
37
+ displayStatusCode = `\x1B[35m${statusCode}\x1B[0m`
38
+ }
39
+ else if (statusCode >= 400) {
40
+ displayStatusCode = `\x1B[31m${statusCode}\x1B[0m`
41
+ }
42
+ else if (statusCode >= 300) {
43
+ displayStatusCode = `\x1B[33m${statusCode}\x1B[0m`
44
+ }
45
+ else if (statusCode >= 200) {
46
+ displayStatusCode = `\x1B[32m${statusCode}\x1B[0m`
47
+ }
48
+ return `${data?.timestamp} ${data?.level} ${data?.ip} ${data?.iso2 || ''} ${data?.accessKey || ''} ${cuid}${data?.controller} ${data?.action}${message} | ${displayStatusCode} | ${data?.performance?.executionTime}ms`
33
49
  }
34
50
  else {
35
51
  const meta = data?.meta
@@ -39,7 +55,7 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
39
55
  let subName = _.get(meta, 'sub') ? _.get(meta, 'sub') + ' | ' : _.get(data, 'sub') ? _.get(data, 'sub') + ' | ' : ''
40
56
 
41
57
  // modern approach (fileName, functionName, sub) // TBD with team
42
- let functionIdentifier = _.get(data, 'functionIdentifier') ? _.get(data, 'functionIdentifier') + ' | ' : ''
58
+ const functionIdentifier = _.get(data, 'functionIdentifier') ? _.get(data, 'functionIdentifier') + ' | ' : ''
43
59
  if (!fileName && _.get(data, 'fileName')) fileName = _.get(data, 'fileName')
44
60
  if (!functionName && _.get(data, 'functionName')) functionName = _.get(data, 'functionName')
45
61
  if (!subName && _.get(data, 'sub')) subName = _.get(data, 'sub')
@@ -48,8 +64,8 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
48
64
  let message = data?.message
49
65
 
50
66
 
51
- let prefix = []
52
- let dataFromPrefix = []
67
+ const prefix = []
68
+ const dataFromPrefix = []
53
69
  _.forEach(prefixFields, item => {
54
70
  if (_.get(meta, _.get(item, 'field'))) {
55
71
  prefix.push(_.get(item, 'short'))
@@ -91,6 +107,7 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
91
107
  // structured logging for analysis and querying within the CloudWatch service.
92
108
  if (applicationLogs?.enabled) {
93
109
  let filename = applicationLogs?.filename || 'application.log'
110
+ const symlinkName = filename
94
111
  if (filename.endsWith('.log')) {
95
112
  // If the filename ends with .log, insert -%DATE% before the extension
96
113
  filename = filename.replace(/\.log$/, '-%DATE%.log');
@@ -111,7 +128,9 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
111
128
  format.timestamp(),
112
129
  splatFormatter(),
113
130
  format.json()
114
- )
131
+ ),
132
+ createSymlink: true, // Enable symlink creation
133
+ symlinkName: symlinkName // Fixed name for the current log file symlink
115
134
  })
116
135
 
117
136
  transport.on('error', error => {
@@ -144,7 +163,15 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
144
163
  const acLogger = createLogger(logConfig)
145
164
  if (_.get(customLevels, 'colors')) addColors(_.get(customLevels, 'colors'))
146
165
 
147
-
166
+ const changeLogLevel = (newLevel) => {
167
+ acLogger.transports.forEach((transport) => {
168
+ const currentLevel = transport.level || acLogger.level; // Fallback to the logger's default level
169
+ if (currentLevel !== newLevel) {
170
+ console.warn(`Changing level of ${transport.name} from ${currentLevel} to ${newLevel}`);
171
+ transport.level = newLevel; // Confirm this line is executing
172
+ }
173
+ });
174
+ };
148
175
 
149
176
  const headline = (params) => {
150
177
  acLogger.info('')
@@ -228,6 +255,7 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
228
255
 
229
256
  return {
230
257
  acLogger,
258
+ changeLogLevel,
231
259
  headline,
232
260
  functionStartLine,
233
261
  listing,
package/package.json CHANGED
@@ -3,19 +3,19 @@
3
3
  "author": "Mark Poepping (https://www.admiralcloud.com)",
4
4
  "license": "MIT",
5
5
  "repository": "admiralcloud/ac-logger",
6
- "version": "2.3.1",
6
+ "version": "3.0.0",
7
7
  "dependencies": {
8
8
  "lodash": "^4.17.21",
9
9
  "moment": "^2.30.1",
10
- "winston": "^3.12.0",
10
+ "winston": "^3.14.1",
11
11
  "winston-daily-rotate-file": "^5.0.0"
12
12
  },
13
13
  "devDependencies": {
14
14
  "ac-semantic-release": "^0.4.2",
15
- "chai": "^4.4.1",
16
- "eslint": "^8.57.0",
15
+ "chai": "^4.5.0",
16
+ "eslint": "^9.8.0",
17
17
  "intercept-stdout": "^0.1.2",
18
- "mocha": "^10.3.0",
18
+ "mocha": "^10.7.3",
19
19
  "mocha-jenkins-reporter": "^0.4.8"
20
20
  },
21
21
  "scripts": {
@@ -23,6 +23,9 @@
23
23
  "test-jenkins": "JUNIT_REPORT_PATH=./report.xml mocha --colors --reporter mocha-jenkins-reporter --reporter-options junit_report_name='ACLogger'"
24
24
  },
25
25
  "engines": {
26
- "node": ">=16.0.0"
26
+ "node": ">=18.0.0"
27
+ },
28
+ "resolutions": {
29
+ "mocha/chokidar/braces": "^3.0.3"
27
30
  }
28
31
  }
package/test/test.js CHANGED
@@ -23,6 +23,30 @@ describe('Tests', () => {
23
23
  expect(lines[9]).to.contain('AppName')
24
24
  expect(lines[9]).to.contain('myApp')
25
25
  })
26
+
27
+
28
+ it('Log info', () => {
29
+ captured_text = ''
30
+ const log = aclog().acLogger
31
+ log.info('Hello Info')
32
+ log.debug('Hello Debug')
33
+ const lines = captured_text.split('\n')
34
+ expect(lines[0]).to.contain('INFO')
35
+ expect(lines[1]).not.to.contain('DEBUG')
36
+ })
37
+
38
+ it('Log debug', () => {
39
+ const loggerSetup = aclog();
40
+ const log = loggerSetup.acLogger
41
+ loggerSetup.changeLogLevel('debug')
42
+ captured_text = ''
43
+ log.info('Hello Info')
44
+ log.debug('Hello Debug')
45
+ const lines = captured_text.split('\n')
46
+ expect(lines[0]).to.contain('INFO')
47
+ expect(lines[1]).to.contain('DEBUG')
48
+ })
49
+
26
50
 
27
51
  it('Unhook', () => {
28
52
  unhook_intercept()
package/.eslintrc.js DELETED
@@ -1,27 +0,0 @@
1
- const config = {
2
- root: true,
3
- 'env': {
4
- 'commonjs': true,
5
- 'es2020': true,
6
- 'node': true
7
- },
8
- 'extends': 'eslint:recommended',
9
- "rules": {
10
- "space-before-function-paren": 0,
11
- "no-extra-semi": 0,
12
- "object-curly-spacing": ["error", "always"],
13
- "brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
14
- "no-useless-escape": 0,
15
- "standard/no-callback-literal": 0,
16
- "new-cap": 0
17
- },
18
- globals: {
19
- describe: true,
20
- it: true
21
- },
22
- 'parserOptions': {
23
- 'ecmaVersion': 2022
24
- },
25
- }
26
-
27
- module.exports = config