Skip to content

Commit a9906c4

Browse files
committed
fix: logFile default to info if undefined, warn if error setting
the existing enum FfiLogLevelFilter was not used, and its values LOG_LEVEL_* as not the same as LogLevel types LogLevel = debug | error | info | trace | warn; This fixes it for the verifier exposed in pact-js, automatically consuming this fix release. pact-js consumer interfaces, still require updating to pass in the logFile argument.
1 parent 9acf43c commit a9906c4

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/ffi/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,14 @@ export const getFfiLib = (
132132
logFile
133133
);
134134
if (logFile) {
135-
logger.debug(
136-
`writing log file at level ${FfiLogLevelFilter[logLevel]} to ${logFile}`
135+
logger.debug(`writing log file at level ${logLevel} to ${logFile}`);
136+
const res = ffiLib.pactffiLogToFile(
137+
logFile,
138+
FfiLogLevelFilter[logLevel] ?? 3
137139
);
138-
const res = ffiLib.pactffiLogToFile(logFile, FfiLogLevelFilter[logLevel]);
139-
logger.debug(`result of writing to file '${res}'`);
140+
if (res !== 0) {
141+
logger.warn(`Failed to write log file to ${logFile}, reason: ${res}`);
142+
}
140143
} else {
141144
ffiLib.pactffiInitWithLogLevel(logLevel);
142145
}

src/ffi/types.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,11 @@ export enum FfiFunctionResult {
110110
}
111111

112112
export enum FfiLogLevelFilter {
113-
LOG_LEVEL_OFF = 0,
114-
LOG_LEVEL_ERROR,
115-
LOG_LEVEL_WARN,
116-
LOG_LEVEL_INFO,
117-
LOG_LEVEL_DEBUG,
118-
LOG_LEVEL_TRACE,
113+
'error' = 1,
114+
'warn' = 2,
115+
'info' = 3,
116+
'debug' = 4,
117+
'trace' = 5,
119118
}
120119

121120
export type Ffi = {

0 commit comments

Comments
 (0)