Socket
Socket
Sign inDemoInstall

@docusaurus/logger

Package Overview
Dependencies
7
Maintainers
4
Versions
981
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @docusaurus/logger

An encapsulated logger for semantically formatting console messages.


Version published
Weekly downloads
349K
decreased by-2.86%
Maintainers
4
Created
Weekly downloads
 

Changelog

Source

3.4.0 (2024-05-31)

:rocket: New Feature
  • create-docusaurus, docusaurus-plugin-content-blog, docusaurus-plugin-content-docs, docusaurus-theme-classic, docusaurus-utils-validation, docusaurus-utils
    • #10137 feat(docs, blog): add support for tags.yml, predefined list of tags (@OzakIOne)
  • docusaurus-theme-translations
    • #10151 feat(theme-translations): Added Turkmen (tk) default theme translations (@ilmedova)
    • #10111 feat(theme-translations): Add Bulgarian default theme translations (bg) (@PetarMc1)
  • docusaurus-plugin-client-redirects, docusaurus-plugin-content-blog, docusaurus-plugin-pwa, docusaurus-plugin-sitemap, docusaurus-theme-search-algolia, docusaurus-types, docusaurus-utils, docusaurus
    • #9859 feat(core): hash router option - browse site offline (experimental) (@slorber)
  • docusaurus-module-type-aliases, docusaurus-theme-classic, docusaurus-theme-common, docusaurus-types, docusaurus
    • #10121 feat(core): site storage config options (experimental) (@slorber)
:bug: Bug Fix
  • docusaurus-plugin-content-blog, docusaurus-plugin-content-docs, docusaurus-utils
    • #10185 fix(docs, blog): Markdown link resolution does not support hot reload (@slorber)
  • docusaurus-theme-search-algolia
    • #10178 fix(theme): SearchPage should respect contextualSearch: false setting (@ncoughlin)
    • #10164 fix(search): fix algolia search container bug (@slorber)
  • docusaurus-mdx-loader, docusaurus-plugin-content-blog, docusaurus-plugin-content-docs, docusaurus-plugin-content-pages, docusaurus-utils
    • #10168 fix(mdx-loader): resolve Markdown/MDX links with Remark instead of RegExp (@slorber)
  • docusaurus-theme-translations
  • docusaurus
    • #10145 fix(core): fix serve workaround regexp (@slorber)
    • #10142 fix(core): fix docusaurus serve broken for assets when using trailingSlash (@slorber)
    • #10130 fix(core): the broken anchor checker should not be sensitive pathname trailing slashes (@slorber)
  • docusaurus-theme-classic, docusaurus-theme-common
    • #10144 fix(theme): fix announcement bar layout shift due to missing storage key namespace (@slorber)
  • docusaurus-plugin-content-docs, docusaurus
    • #10132 fix(core): configurePostCss() should run after configureWebpack() (@slorber)
  • docusaurus-utils, docusaurus
    • #10131 fix(core): codegen should generate unique route prop filenames (@slorber)
  • docusaurus-theme-classic, docusaurus-theme-translations
    • #10118 fix(theme-translations): fix missing pluralization for label DocCard.categoryDescription.plurals (@slorber)
:memo: Documentation
  • #10176 docs: add community plugin docusaurus-graph (@Arsero)
  • #10173 docs: improve how to use <details> (@tats-u)
  • #10167 docs: suggest using {<...>...</...>} if don't use Markdown in migra… (@tats-u)
  • #10143 docs: recommend users to remove hast-util-is-element in migration to v3 (@tats-u)
  • #10124 docs: v3 prepare your site blog post should point users to the upgrade guide (@homotechsual)
:robot: Dependencies
Committers: 11

Readme

Source

@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 a ReportingSeverity 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:

Some text output in the terminal, containing array, code, name, and number formatting

FAQs

Last updated on 31 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc