-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add pactffi_log_to_file for consumer/verifier #428
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import path from 'node:path'; | |
import bindings = require('node-gyp-build'); | ||
import logger, { DEFAULT_LOG_LEVEL } from '../logger'; | ||
import { LogLevel } from '../logger/types'; | ||
import { Ffi } from './types'; | ||
import { Ffi, FfiLogLevelFilter } from './types'; | ||
|
||
export const PACT_FFI_VERSION = '0.4.22'; | ||
|
||
|
@@ -85,18 +85,15 @@ const renderBinaryErrorMessage = (error: unknown) => { | |
}; | ||
|
||
let ffi: typeof ffiLib; | ||
let ffiLogLevel: LogLevel; | ||
|
||
const initialiseFfi = (logLevel: LogLevel): typeof ffi => { | ||
const initialiseFfi = (): typeof ffi => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
if (process.stdout._handle) { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
process.stdout._handle.setBlocking(true); | ||
} | ||
logger.debug(`Initalising native core at log level '${logLevel}'`); | ||
ffiLogLevel = logLevel; | ||
try { | ||
bindingPaths.every((bindingPath, i) => { | ||
try { | ||
|
@@ -114,7 +111,6 @@ const initialiseFfi = (logLevel: LogLevel): typeof ffi => { | |
return true; | ||
} | ||
}); | ||
ffiLib.pactffiInitWithLogLevel(logLevel); | ||
} catch (error) { | ||
renderBinaryErrorMessage(error); | ||
throw new Error( | ||
|
@@ -125,18 +121,24 @@ const initialiseFfi = (logLevel: LogLevel): typeof ffi => { | |
}; | ||
|
||
export const getFfiLib = ( | ||
logLevel: LogLevel = DEFAULT_LOG_LEVEL | ||
logLevel: LogLevel = DEFAULT_LOG_LEVEL, | ||
logFile: string | undefined = undefined | ||
): typeof ffi => { | ||
if (!ffi) { | ||
logger.trace('Initiliasing ffi for the first time'); | ||
ffi = initialiseFfi(logLevel); | ||
} else { | ||
logger.trace('Ffi has already been initialised, no need to repeat it'); | ||
if (logLevel !== ffiLogLevel) { | ||
logger.warn( | ||
`The pact native core has already been initialised at log level '${ffiLogLevel}'` | ||
logger.trace('Initialising ffi for the first time'); | ||
ffi = initialiseFfi(); | ||
logger.debug( | ||
`Initialising native core at log level '${logLevel}'`, | ||
logFile | ||
); | ||
if (logFile) { | ||
logger.debug( | ||
`writing log file at level ${FfiLogLevelFilter[logLevel]} to ${logFile}` | ||
); | ||
logger.warn(`The new requested log level '${logLevel}' will be ignored`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we missing handling the error in this scenario (somebody initialising the FFI more than once with a different log level)? |
||
const res = ffiLib.pactffiLogToFile(logFile, FfiLogLevelFilter[logLevel]); | ||
logger.debug(`result of writing to file '${res}'`); | ||
} else { | ||
ffiLib.pactffiInitWithLogLevel(logLevel); | ||
} | ||
} | ||
return ffi; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
err
defined somewhere?