refactor: unify log format with new logger utility (#5994)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Joshua Chen 2021-12-21 00:24:59 +08:00 committed by GitHub
parent faef753730
commit 770418f8d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 717 additions and 650 deletions

View file

@ -57,7 +57,7 @@ describe('DefaultSidebarItemsGenerator', () => {
expect(sidebarSlice).toEqual([]);
expect(consoleWarn).toHaveBeenCalledWith(
expect.stringMatching(
/No docs found in dir .: can't auto-generate a sidebar/,
/.*\[WARNING\].* No docs found in .*\..*: can't auto-generate a sidebar\..*/,
),
);
});

View file

@ -16,7 +16,7 @@ import type {
} from './types';
import {sortBy, last} from 'lodash';
import {addTrailingSlash, posixPath} from '@docusaurus/utils';
import chalk from 'chalk';
import logger from '@docusaurus/logger';
import path from 'path';
import fs from 'fs-extra';
import Yaml from 'js-yaml';
@ -72,11 +72,7 @@ async function readCategoryMetadataFile(
try {
return validateCategoryMetadataFile(unsafeContent);
} catch (e) {
console.error(
chalk.red(
`The docs sidebar category metadata file looks invalid!\nPath: ${filePath}`,
),
);
logger.error`The docs sidebar category metadata file path=${filePath} looks invalid!`;
throw e;
}
}
@ -134,11 +130,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
const docs = allDocs.filter(isInAutogeneratedDir);
if (docs.length === 0) {
console.warn(
chalk.yellow(
`No docs found in dir ${autogenDir}: can't auto-generate a sidebar.`,
),
);
logger.warn`No docs found in path=${autogenDir}: can't auto-generate a sidebar.`;
}
return docs;
}