Skip to content

Commit 09974e8

Browse files
committed
docs(changeset): Improve logging
1 parent 517f175 commit 09974e8

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

.changeset/hot-yaks-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"git-json-resolver": patch
3+
---
4+
5+
Improve logging

lib/src/merge-processor.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const processMerge = async <T extends string = InbuiltMergeStrategies>({
4949
strategies: normalizedConfig.customStrategies ?? {},
5050
_strategyCache,
5151
},
52+
logger,
5253
}),
5354
backupFile(filePath, config.backupDir),
5455
]);
@@ -99,12 +100,10 @@ export const resolveGitMergeFiles = async <T extends string = InbuiltMergeStrate
99100
const globalLogger = await createLogger(config.loggerConfig, config.debug);
100101
const normalizedConfig: NormalizedConfig = await normalizeConfig<T>(config);
101102

102-
if (normalizedConfig.debug) {
103-
globalLogger.info(
104-
"git-merge",
105-
`Merging files: ours=${oursPath}, base=${basePath}, theirs=${theirsPath}`,
106-
);
107-
}
103+
globalLogger.debug(
104+
"git-merge",
105+
`Merging files: ours=${oursPath}, base=${basePath}, theirs=${theirsPath}`,
106+
);
108107

109108
const [oursContent, baseContent, theirsContent] = await Promise.all([
110109
fs.readFile(oursPath, "utf8"),

lib/src/merger.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createLogger } from "./logger";
12
import { NormalizedConfig } from "./normalizer";
23
import { resolveStrategies } from "./strategy-resolver";
34
import { StrategyFn, StrategyResult, StrategyStatus } from "./types";
@@ -59,6 +60,7 @@ interface MergeArgs<TContext> {
5960
filePath?: string;
6061
ctx: MergeContext<TContext>;
6162
conflicts: Conflict[];
63+
logger: Awaited<ReturnType<typeof createLogger>>;
6264
}
6365

6466
/** Utility: plain-object check. */
@@ -105,7 +107,7 @@ export const BuiltInStrategies = {
105107
},
106108

107109
merge: async <TContext>(args: MergeArgs<TContext>): Promise<StrategyResult> => {
108-
const { ours, theirs, base, path, filePath, ctx, conflicts } = args;
110+
const { ours, theirs, base, path, filePath, ctx, conflicts, logger } = args;
109111

110112
// Plain objects
111113
if (isPlainObject(ours) && isPlainObject(theirs)) {
@@ -120,6 +122,7 @@ export const BuiltInStrategies = {
120122
filePath,
121123
ctx,
122124
conflicts,
125+
logger,
123126
});
124127
}
125128
return { status: StrategyStatus_OK, value: result };
@@ -164,6 +167,7 @@ export const mergeObject = async <TContext>({
164167
filePath,
165168
ctx,
166169
conflicts,
170+
logger,
167171
}: MergeArgs<TContext>): Promise<unknown> => {
168172
if (ours === theirs) return ours;
169173

@@ -175,6 +179,8 @@ export const mergeObject = async <TContext>({
175179
ctx._strategyCache.set(path, strategies);
176180
}
177181

182+
logger.debug(filePath ?? "all", `path: ${path}, strategies: ${strategies.join(", ") || "none"}`);
183+
178184
for (const strategy of strategies) {
179185
const fn = (BuiltInStrategies as any)[strategy] ?? ctx.strategies[strategy];
180186

@@ -188,6 +194,7 @@ export const mergeObject = async <TContext>({
188194
filePath,
189195
ctx,
190196
conflicts,
197+
logger,
191198
});
192199

193200
switch (result.status) {

0 commit comments

Comments
 (0)