x-fidelity 3.15.0 → 3.16.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,10 @@
1
+ # [3.16.0](https://github.com/zotoio/x-fidelity/compare/v3.15.0...v3.16.0) (2025-03-19)
2
+
3
+
4
+ ### Features
5
+
6
+ * add support for disabling colored logging via XFI_LOG_COLOR env var ([cafcf5b](https://github.com/zotoio/x-fidelity/commit/cafcf5b6fde9b29dbe31a62cba491ab42c24b759))
7
+
1
8
  # [3.15.0](https://github.com/zotoio/x-fidelity/compare/v3.14.0...v3.15.0) (2025-03-12)
2
9
 
3
10
 
package/README.md CHANGED
@@ -50,6 +50,7 @@ x-fidelity is an advanced CLI tool and paired config server designed to perform
50
50
  - [Basic Usage](#basic-usage)
51
51
  - [Advanced Usage](#advanced-usage)
52
52
  - [Environment Variables](#environment-variables)
53
+ - [Logging Options](#logging-options)
53
54
  - [Local Configuration](#local-configuration)
54
55
  - [Remote Configuration](#remote-configuration)
55
56
  8. [Hosting Config Servers](#hosting-config-servers)
@@ -475,6 +476,7 @@ x-fidelity supports the following environment variables:
475
476
  - `CERT_PATH`: The path to SSL certificates for HTTPS config server.
476
477
  - `NODE_TLS_REJECT_UNAUTHORIZED`: Set to '0' to allow self-signed certificates (use with caution).
477
478
  - `XFI_SHARED_SECRET`: Shared secret for securing telemetry and certain server routes.
479
+ - `XFI_LOG_COLOR`: Set to 'false' to disable colored output in logs.
478
480
 
479
481
  Example usage:
480
482
 
@@ -483,6 +485,7 @@ export OPENAI_API_KEY=your_api_key_here
483
485
  export OPENAI_MODEL=gpt-4
484
486
  export XFI_LISTEN_PORT=9999
485
487
  export XFI_SHARED_SECRET=your_shared_secret_here
488
+ export XFI_LOG_COLOR=false
486
489
  xfidelity -o true
487
490
  ```
488
491
 
@@ -500,6 +503,23 @@ The local config directory should contain:
500
503
 
501
504
  You can override default archetypes or add new ones by placing the corresponding JSON files in the local config directory.
502
505
 
506
+ ### Logging Options
507
+
508
+ x-fidelity provides options to customize the logging output:
509
+
510
+ 1. **Log Level**: Set the logging level using the `XFI_LOG_LEVEL` environment variable:
511
+ ```sh
512
+ export XFI_LOG_LEVEL=debug
513
+ ```
514
+ Available levels: trace, debug, info, warn, error, fatal
515
+
516
+ 2. **Colored Output**: You can disable colored logging output using an environment variable:
517
+ ```sh
518
+ export XFI_LOG_COLOR=false
519
+ ```
520
+
521
+ This is particularly useful in CI/CD environments or when redirecting logs to files.
522
+
503
523
  ### Remote Configuration
504
524
 
505
525
  To use a remote configuration server, use the `-c` or `--configServer` option:
@@ -17,7 +17,7 @@
17
17
  "cognitiveComplexity": 30,
18
18
  "nestingDepth": 10,
19
19
  "parameterCount": 5,
20
- "returnCount": 5
20
+ "returnCount": 10
21
21
  }
22
22
  },
23
23
  "operator": "astComplexity",
@@ -26,7 +26,7 @@
26
26
  "cognitiveComplexity": 30,
27
27
  "nestingDepth": 10,
28
28
  "parameterCount": 5,
29
- "returnCount": 5
29
+ "returnCount": 10
30
30
  }
31
31
  }
32
32
  ]
@@ -38,6 +38,8 @@ function getLogPrefix() {
38
38
  }
39
39
  // Initialize logger function that will create the singleton if it doesn't exist
40
40
  function getLogger(force) {
41
+ // Determine if color should be enabled based on environment variable only
42
+ const useColor = process.env.XFI_LOG_COLOR !== 'false';
41
43
  if (!loggerInstance || force) {
42
44
  const fileTransport = pino_1.default.destination({
43
45
  dest: 'x-fidelity.log',
@@ -49,7 +51,7 @@ function getLogger(force) {
49
51
  options: {
50
52
  loglevel: loglevel,
51
53
  sync: false,
52
- colorize: true,
54
+ colorize: useColor,
53
55
  translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l o',
54
56
  ignore: 'pid,hostname',
55
57
  singleLine: true,
@@ -2,6 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const logger_1 = require("./logger");
4
4
  describe('Logger utilities', () => {
5
+ // Save original environment
6
+ const originalEnv = process.env;
7
+ beforeEach(() => {
8
+ // Reset environment before each test
9
+ process.env = Object.assign({}, originalEnv);
10
+ });
11
+ afterAll(() => {
12
+ // Restore original environment
13
+ process.env = originalEnv;
14
+ });
5
15
  describe('generateLogPrefix', () => {
6
16
  it('should generate a string of length 8', () => {
7
17
  const prefix = (0, logger_1.generateLogPrefix)();
@@ -29,4 +39,13 @@ describe('Logger utilities', () => {
29
39
  expect(newPrefix.length).toBe(8);
30
40
  });
31
41
  });
42
+ describe('logger color configuration', () => {
43
+ it('should respect XFI_LOG_COLOR environment variable', () => {
44
+ process.env.XFI_LOG_COLOR = 'false';
45
+ (0, logger_1.resetLogger)();
46
+ // This test doesn't directly assert the colorize option
47
+ // as it's internal to pino, but ensures the code path is executed
48
+ expect(process.env.XFI_LOG_COLOR).toBe('false');
49
+ });
50
+ });
32
51
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-fidelity",
3
- "version": "3.15.0",
3
+ "version": "3.16.0",
4
4
  "description": "cli for opinionated framework adherence checks",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "cognitiveComplexity": 30,
18
18
  "nestingDepth": 10,
19
19
  "parameterCount": 5,
20
- "returnCount": 5
20
+ "returnCount": 10
21
21
  }
22
22
  },
23
23
  "operator": "astComplexity",
@@ -26,7 +26,7 @@
26
26
  "cognitiveComplexity": 30,
27
27
  "nestingDepth": 10,
28
28
  "parameterCount": 5,
29
- "returnCount": 5
29
+ "returnCount": 10
30
30
  }
31
31
  }
32
32
  ]
@@ -17,7 +17,7 @@
17
17
  "cognitiveComplexity": 30,
18
18
  "nestingDepth": 10,
19
19
  "parameterCount": 5,
20
- "returnCount": 5
20
+ "returnCount": 10
21
21
  }
22
22
  },
23
23
  "operator": "astComplexity",
@@ -26,7 +26,7 @@
26
26
  "cognitiveComplexity": 30,
27
27
  "nestingDepth": 10,
28
28
  "parameterCount": 5,
29
- "returnCount": 5
29
+ "returnCount": 10
30
30
  }
31
31
  }
32
32
  ]
@@ -1,6 +1,18 @@
1
- import { generateLogPrefix, setLogPrefix, getLogPrefix, resetLogPrefix } from './logger';
1
+ import { generateLogPrefix, setLogPrefix, getLogPrefix, resetLogPrefix, resetLogger } from './logger';
2
2
 
3
3
  describe('Logger utilities', () => {
4
+ // Save original environment
5
+ const originalEnv = process.env;
6
+
7
+ beforeEach(() => {
8
+ // Reset environment before each test
9
+ process.env = { ...originalEnv };
10
+ });
11
+
12
+ afterAll(() => {
13
+ // Restore original environment
14
+ process.env = originalEnv;
15
+ });
4
16
  describe('generateLogPrefix', () => {
5
17
  it('should generate a string of length 8', () => {
6
18
  const prefix = generateLogPrefix();
@@ -31,4 +43,14 @@ describe('Logger utilities', () => {
31
43
  expect(newPrefix.length).toBe(8);
32
44
  });
33
45
  });
46
+
47
+ describe('logger color configuration', () => {
48
+ it('should respect XFI_LOG_COLOR environment variable', () => {
49
+ process.env.XFI_LOG_COLOR = 'false';
50
+ resetLogger();
51
+ // This test doesn't directly assert the colorize option
52
+ // as it's internal to pino, but ensures the code path is executed
53
+ expect(process.env.XFI_LOG_COLOR).toBe('false');
54
+ });
55
+ });
34
56
  });
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from 'crypto';
2
2
  import pino from 'pino';
3
3
  import { maskSensitiveData } from './maskSensitiveData';
4
+ import { options } from '../core/cli';
4
5
 
5
6
  // Initialize variables
6
7
  let loggerInstance: pino.Logger | undefined;
@@ -32,6 +33,9 @@ export function getLogPrefix(): string {
32
33
 
33
34
  // Initialize logger function that will create the singleton if it doesn't exist
34
35
  function getLogger(force?: boolean): pino.Logger {
36
+ // Determine if color should be enabled based on environment variable only
37
+ const useColor = process.env.XFI_LOG_COLOR !== 'false';
38
+
35
39
  if (!loggerInstance || force) {
36
40
  const fileTransport = pino.destination({
37
41
  dest: 'x-fidelity.log',
@@ -44,7 +48,7 @@ function getLogger(force?: boolean): pino.Logger {
44
48
  options: {
45
49
  loglevel: loglevel,
46
50
  sync: false,
47
- colorize: true,
51
+ colorize: useColor,
48
52
  translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l o',
49
53
  ignore: 'pid,hostname',
50
54
  singleLine: true,
@@ -42,8 +42,15 @@ GITHUB_WEBHOOK_SECRET=your_github_webhook_secret
42
42
  ```bash
43
43
  # Set logging level (default: 'info')
44
44
  XFI_LOG_LEVEL=debug
45
+
46
+ # Disable colored output in logs (default: enabled)
47
+ XFI_LOG_COLOR=false
45
48
  ```
46
49
 
50
+ The `XFI_LOG_COLOR` environment variable controls whether log output includes ANSI color codes. This is particularly useful in CI/CD environments, when redirecting logs to files, or when your terminal doesn't support colors.
51
+
52
+ Setting `XFI_LOG_COLOR=false` will disable all colored output in logs, making them plain text. This can improve readability in environments where color codes might appear as strange characters.
53
+
47
54
  ## Usage Examples
48
55
 
49
56
  ### Basic Setup
@@ -62,6 +62,7 @@ Options:
62
62
  - `CERT_PATH`: SSL certificate path
63
63
  - `NODE_TLS_REJECT_UNAUTHORIZED`: Allow self-signed certs
64
64
  - `XFI_SHARED_SECRET`: Shared secret for security
65
+ - `XFI_LOG_COLOR`: Set to 'false' to disable colored output in logs
65
66
  - `NOTIFICATIONS_ENABLED`: Enable notification system
66
67
  - `NOTIFICATION_PROVIDERS`: Comma-separated list of notification providers to use
67
68
  - `CODEOWNERS_PATH`: Path to CODEOWNERS file (default: .github/CODEOWNERS)