pwa-kit
pwa-kit copied to clipboard
@W-15634851@ [Spike] Filter PWA Kit server-side logs via a defined log level
Description
The solution ensures all logs are managed according to the specified log level by adding a new logger that overrides the console object and substitutes it with a custom logger using Winston.
The log level can be adjusted via the TESTMRT_LOG_LEVEL
environment variable.
The 3pp winston is already approved.
Types of Changes
- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
- [ ] Documentation update
- [ ] Breaking change (could cause existing functionality to not work as expected)
- [ ] Other changes (non-breaking changes that does not fit any of the above)
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
- Override the console object with a custom logger using Winston in pwa-kit-react-sdk and pwa-kit-runtime.
How to Test-Drive This PR
A bundle has been published with some test console statements in the _app component on the test-env-2
.
if (isServer) {
console.debug('PWAKITLOG >>> _app: console.debug')
console.info('PWAKITLOG >>> _app: console.info')
console.log('PWAKITLOG >>> _app: console.log')
console.warn('PWAKITLOG >>> _app: console.warn')
console.error('PWAKITLOG >>> _app: console.error')
}
- Run the tail-logs command against the
test-env-2
environment.
npx @salesforce/pwa-kit-dev@latest tail-logs --project scaffold-pwa --environment test-env-2
- Adjust the
TESTMRT_LOG_LEVEL
value to "warn" using our cloud api key.
curl --location --request PATCH 'https://cloud.mobify.com/api/projects/scaffold-pwa/target/test-env-2/env-var/' \
--header 'Authorization: Bearer your-cloud-api-key' \
--header 'Content-Type: application/json' \
--data '{
"TESTMRT_LOG_LEVEL": {"value": "warn"}
}'
-
Load the bundle home page
/
: https://scaffold-pwa-test-env-2.mobify-storefront.com/ -
Verify that only logs with the log level "warn" and above are visible.
- 1️⃣ Incoming HTTP request using Morgan [pwa-kit-runtime]
- 2️⃣ Express app Request ID and the CloudFront ID [pwa-kit-runtime]
- 3️⃣ PWA Kit and other packages console warn and error statements
- 4️⃣ User’s console statements declared in the template-retail-react-app
- Repeat the same adjusting the
TESTMRT_LOG_LEVEL
value to "info".
Checklists
General
- [ ] Changes are covered by test cases
- [ ] CHANGELOG.md updated with a short description of changes (not required for documentation updates)
Accessibility Compliance
You must check off all items in one of the follow two lists:
- [ ] There are no changes to UI
or...
- [ ] Changes were tested with a Screen Reader (iOS VoiceOver or Android Talkback) and had no issues
- [ ] Changes comply with WCAG 2.0 guidelines levels A and AA
- [ ] Changes to common UI patterns and interactions comply with WAI-ARIA best practices
Localization
- [ ] Changes include a UI text update in the Retail React App (which requires translation)