Skip to content

Commit

Permalink
feat: allow setting of LOG_LEVEL env var
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Jul 5, 2023
1 parent f9fd3c4 commit 7224770
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ var pact = require("@pact-foundation/pact-core");
pact.logLevel("debug");
```

or you can set it via an environment variable

```
LOG_LEVEL=debug
```

### Mock Servers

Mock servers are used by Pact to record interactions and create pact contracts.
Expand All @@ -166,7 +172,7 @@ var server = pact.createServer({
| `port` | false | number | Port number that the server runs on, defaults to random available port |
| `host` | false | string | Host on which to bind the server on, defaults to 'localhost'. Supports '0.0.0.0' to bind on all IPv4 addresses on the local machine. |
| `log` | false | string | File to log output on relative to current working directory, defaults to none |
| `logLevel` | false | LogLevel (string) | Log level to pass to the pact core. One of "DEBUG", "ERROR", "WARN", "INFO" |
| `logLevel` | false | LogLevel (string) | Log level to pass to the pact core. One of "DEBUG", "ERROR", "WARN", "INFO", can be set by LOG_LEVEL env var |
| `ssl` | false | boolean | Create a self-signed SSL cert to run the server over HTTPS , defaults to `false` |
| `sslcert` | false | string | Path to a custom self-signed SSL cert file, 'ssl' option must be set to true to use this option, defaults to none |
| `sslkey` | false | string | Path a custom key and self-signed SSL cert key file, 'ssl' option must be set to true to use this, defaults to none |
Expand Down Expand Up @@ -295,7 +301,7 @@ pact.verifyPacts({
| `providerVersion` | false | string | Provider version, required to publish verification result to Broker. Optional otherwise. |
| `enablePending` | false | boolean | Enable the [pending pacts](https://docs.pact.io/pending) feature. |
| `timeout` | false | number | The duration in ms we should wait to confirm verification process was successful. Defaults to 30000. |
| `logLevel` | false | LogLevel (string) | Log level. One of "TRACE", "DEBUG", "ERROR", "WARN", "INFO" |
| `logLevel` | false | LogLevel (string) | Log level. One of "TRACE", "DEBUG", "ERROR", "WARN", "INFO", can be set by LOG_LEVEL env var |

The consumer version selector looks like this:

Expand Down Expand Up @@ -410,7 +416,7 @@ var server = pact.createStub({
| port | false | number | Port number that the server runs on, defaults to random available port |
| host | false | string | Host on which to bind the server on, defaults to 'localhost'. Supports '0.0.0.0' to bind on all IPv4 addresses on the local machine. |
| log | false | string | File to log output on relative to current working directory, defaults to none |
| logLevel | false | LogLevel (string) | Log level to pass to the pact core. One of "DEBUG", "ERROR", "WARN", "INFO" |
| logLevel | false | LogLevel (string) | Log level to pass to the pact core. One of "DEBUG", "ERROR", "WARN", "INFO", can be set by LOG_LEVEL env var |
| ssl | false | boolean | Create a self-signed SSL cert to run the server over HTTPS , defaults to 'false' |
| sslcert | false | string | Path to a custom self-signed SSL cert file, 'ssl' option must be set to true to use this option. Defaults false | to none |
| sslkey | false | string | Path a custom key and self-signed SSL cert key file, 'ssl' option must be set to true to use this option false. Defaults to none |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"build": "tsc --project tsconfig.build.json",
"prerelease": "npm run snyk-protect",
"release": "commit-and-tag-version",
"test": "cross-env LOGLEVEL=debug PACT_DO_NOT_TRACK=true mocha \"{src,test,bin,standalone}/**/*.spec.ts\"",
"test": "cross-env LOG_LEVEL=debug PACT_DO_NOT_TRACK=true mocha \"{src,test,bin,standalone}/**/*.spec.ts\"",
"snyk-protect": "snyk-protect",
"format:base": "prettier --parser typescript",
"format:check": "npm run format:base -- --list-different \"{src,standalone,bin,test}/**/*.{ts,tsx}\"",
Expand Down
4 changes: 3 additions & 1 deletion src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { LogLevel } from './types';
const pkg = require('../../package.json');

const logContext = `pact-core@${pkg.version}`;
let currentLogLevel: LogLevel = 'info';
let currentLogLevel: LogLevel = process.env['LOG_LEVEL']
? (process.env['LOG_LEVEL'] as LogLevel)
: 'info';
let logger = createLogger(currentLogLevel);

export const DEFAULT_LOG_LEVEL = 'info';
Expand Down

0 comments on commit 7224770

Please sign in to comment.