Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: Joey Clover <joey@popos.local> Co-authored-by: reece-white <93522192+reece-white@users.noreply.github.com> Co-authored-by: Shreesh Nautiyal <114166000+Shreesh09@users.noreply.github.com> Co-authored-by: Nick Gerleman <nick@nickgerleman.com> Co-authored-by: Chongyi Zheng <git@zcy.dev> Co-authored-by: MCR Studio <99176216+mcrstudio@users.noreply.github.com> Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com> Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com> Co-authored-by: Ivan Mar (sOkam!) <7308253+heysokam@users.noreply.github.com> Co-authored-by: c0h1b4 <dwidman@gmail.com> Co-authored-by: Janessa Garrow <janessa.garrow@gmail.com> Co-authored-by: ozaki <29860391+OzakIOne@users.noreply.github.com> Co-authored-by: axmmisaka <6500159+axmmisaka@users.noreply.github.com> Co-authored-by: Tatsunori Uchino <tats.u@live.jp> Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com> Co-authored-by: Sanjaiyan Parthipan <parthipankalayini@gmail.com> Co-authored-by: Jack Robson <143492403+jack-robson@users.noreply.github.com> Co-authored-by: dawei-wang <dawei-wang@users.noreply.github.com> Co-authored-by: eitsupi <50911393+eitsupi@users.noreply.github.com> fix(create-docusaurus): fix readme docusaurus 2 ref (#9487) fix(theme): fix firefox CSS :has() support bug (#9530) fix(theme): docs html sidebar items should always be visible (#9531) fix: v3 admonitions should support v2 title syntax for nested admonitions (#9535) fix(theme-classic): fixed wrong cursor on dropdown menu in navbar, when window is small (#9398) fix(theme): upgrade prism-react-renderer, fix html script and style tag highlighting (#9567) fix: add v2 retrocompatible support for quoted admonitions (#9570) fix(i18n): complete translations for theme-common.json Brazilian Portuguese (pt-BR) (#9477) fix(content-blog): add baseUrl for author.image_url (#9581) fix(type-aliases): add `title` prop for imported inline SVG React components (#9612) fix(utils): Markdown link replacement with <> but no spaces (#9617) fix(live-codeblock): stabilize react-live transformCode callback, fix editor/preview desync (#9631) fix(cli): output help when no conventional config + no subcommand (#9648) fix CI job (#9604) fix Lint Autofix workflow (#9632) fix(pwa-plugin): upgrade workbox (#9668) fix(create-docusaurus): fix init template code blocks, and little improvements (#9696) fix(theme): allow empty code blocks and live playgrounds (#9704) fix(core): various broken anchor link fixes (#9732) fix: remove old useless mdx typedefs (#9733) fix(theme-common): fix missing code block MagicComments style in Visual Basic (.NET) 16 (#9727) fix(core): conditionally include `hostname` parameter when using… (#9407) fix(create-docusaurus): fix typo in init template sample docs (#9783) fix(mdx-loader): allow spaces before `mdx-code-block` info string (#9776) fix(core): links with target "_blank" should no be checked by the broken link checker (#9788) fix(core): broken links optimization behaves differently than non-optimized logic (#9791) |
||
---|---|---|
.. | ||
src | ||
.npmignore | ||
demo.png | ||
package.json | ||
README.md | ||
tsconfig.json |
@docusaurus/logger
An encapsulated logger for semantically formatting console messages.
APIs
It exports a single object as default export: logger
. logger
has the following properties:
- Some useful colors.
red
yellow
green
bold
dim
- Formatters. These functions all have the signature
(msg: unknown) => string
. Note that their implementations are not guaranteed. You should only care about their semantics.path
: formats a file path.url
: formats a URL.name
: formats an identifier.code
: formats a code snippet.subdue
: subdues the text.num
: formats a number.
- The
interpolate
function. It is a template literal tag. The syntax can be found below. - Logging functions. All logging functions can both be used as normal functions (similar to the
console.log
family, but only accepts one parameter) or template literal tags.info
: prints information.warn
: prints a warning that should be paid attention to.error
: prints an error (not necessarily halting the program) that signals significant problems.success
: prints a success message.
- The
report
function. It takes aReportingSeverity
value (ignore
,log
,warn
,throw
) and reports a message according to the severity.
A word on the error
formatter
Beware that an error
message, even when it doesn't hang the program, is likely going to cause confusion. When users inspect logs and find an [ERROR]
, even when the build succeeds, they will assume something is going wrong. Use it sparingly.
Docusaurus only uses logger.error
when printing messages immediately before throwing an error, or when user has set the reporting severity of onBrokenLink
, etc. to "error"
.
In addition, warn
and error
will color the entire message for better attention. If you are printing large blocks of help text about an error, better use logger.info
.
Using the template literal tag
The template literal tag evaluates the template and expressions embedded. interpolate
returns a new string, while other logging functions prints it. Below is a typical usage:
import logger from '@docusaurus/logger';
logger.info`Hello name=${name}! You have number=${money} dollars. Here are the ${
items.length > 1 ? 'items' : 'item'
} on the shelf: ${items}
To buy anything, enter code=${'buy x'} where code=${'x'} is the item's name; to quit, press code=${'Ctrl + C'}.`;
An embedded expression is optionally preceded by a flag in the form [a-z]+=
(a few lowercase letters, followed by an equals sign, directly preceding the embedded expression). If the expression is not preceded by any flag, it's printed out as-is. Otherwise, it's formatted with one of the formatters:
path=
:path
url=
:url
name=
:name
code=
:code
subdue=
:subdue
number=
:num
If the expression is an array, it's formatted by `\n- ${array.join('\n- ')}\n`
(note it automatically gets a leading line end). Each member is formatted by itself and the bullet is not formatted. So you would see the above message printed as: