SalesforceCommerceCloud / pwa-kit

React-based JavaScript frontend framework to create a progressive web app (PWA) storefront for Salesforce B2C Commerce.
https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pwa-kit-overview.html
BSD 3-Clause "New" or "Revised" License
276 stars 126 forks source link

Consistent logs (@W-15832306@) #1822

Closed adamraya closed 3 weeks ago

adamraya commented 1 month ago

Description

The PR implements a createLogger instance for each package to be used by the logs generated in the PWA Kit packages. The logger uses the console object adding a consistent format to the message we want to print.

  1. Proposes a consistent namespace for all default logs generated by PWA Kit to facilitate filtering and analyzing logs. 1.1. The namespace consists of 'packageName.component.action' where the log message is printed. 1.2. The optional additionalProperties defines any other additional properties to include in the log message.

  2. Incoming request logs use the log level equivalent to the response status code. i.e. console.info for statusCode<400 console.error for statusCode >= 400

~~3. The environment variable PWAKIT_LOG_LEVEL defines the log level to filter the logs generated by PWA Kit server-side.

  1. The environment variable PWAKIT_LOG_FORMAT defines the format in which to print log messages server-side. It can be 'JSON' or 'TEXT'.
  2. The createLogger clientConfig object optional parameter allows users to define the format and logLevel for the client-side logs. E.g. createLogger('package-name', clientConfig(format, logLevel)~~

Example using the logger utility: https://github.com/SalesforceCommerceCloud/pwa-kit/blob/05d7c8b0e0f00f48f2af989513b869bd50794290/packages/template-retail-react-app/app/components/_app/index.jsx#L157-L168

Related PR https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1828: Replace all the console statements in PWA Kit with the equivalent logger

Types of Changes

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

How to Test-Drive This PR

Checklists

General

Accessibility Compliance

You must check off all items in one of the follow two lists:

or...

Localization