Skip to content

Commit

Permalink
Merge pull request #1839 from SUI-Components/feat/sui-logger
Browse files Browse the repository at this point in the history
feat(packages/sui-logger): Migrate sui-logger from inner source
  • Loading branch information
nucliweb authored Oct 11, 2024
2 parents efff08e + 3b13263 commit 7be7e24
Show file tree
Hide file tree
Showing 22 changed files with 3,652 additions and 3,198 deletions.
4,458 changes: 1,260 additions & 3,198 deletions package-lock.json

Large diffs are not rendered by default.

452 changes: 452 additions & 0 deletions packages/sui-logger/README.md

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions packages/sui-logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@s-ui/logger",
"version": "1.0.0",
"description": "Web app logger for both client and server side",
"main": "lib/index.js",
"scripts": {
"lib": "babel --presets sui ./src --out-dir ./lib",
"lint": "sui-lint js",
"prepublishOnly": "rm -rf ./lib && npm run lib",
"test": "npm run test:server && npm run test:browser",
"test:browser": "NODE_ENV=test sui-test browser -P './test/browser/*Spec.js' -H",
"test:server": "NODE_ENV=test sui-test server -P './test/server/*Spec.js'"
},
"license": "MIT",
"peerDependencies": {
"react": "16 || 17"
},
"dependencies": {
"@s-ui/react-router": "1",
"bunyan": "1.8.12",
"bunyan-middleware": "1.0.0",
"hot-shots": "7.7.1"
},
"devDependencies": {
"@babel/cli": "7.15.7",
"@s-ui/bundler": "9",
"@s-ui/lint": "4",
"@s-ui/mono": "2",
"@s-ui/test": "8",
"babel-preset-sui": "3",
"chai": "4.3.4",
"react": "17",
"sinon": "11.1.2"
},
"config": {
"sui-test": {
"server": {
"esmOverride": true,
"useLibDir": true
}
}
}
}
19 changes: 19 additions & 0 deletions packages/sui-logger/src/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import createLogger from './logger'

export const createClientLogger = ({userId, trackerName} = {}) =>
createLogger({
listenUnhandled: logError => {
const handleWindowError = e => {
const error = e.reason || e.error

logError(error)
}

window.addEventListener('error', handleWindowError)
window.addEventListener('unhandledrejection', handleWindowError)
},
userAgent: window.navigator.userAgent,
trackerName,
userId,
getUrlFactory: () => window.location.href
})
15 changes: 15 additions & 0 deletions packages/sui-logger/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {NODE_ENV} = process.env
const isServer = typeof window === 'undefined' ? 'true' : 'false'

export {createClientLogger} from './client.js'
export {createServerLogger, logErrorsMiddleware} from './server.js'
export {traceInitialProps} from './traceInitialProps.js'

export const initTracker = ({Mushroom, appName, environment, version, tenant, ...config}) => {
const context = {environment: environment || NODE_ENV, isServer, version, tenant}

Mushroom.start(appName, {
...config,
context
})
}
Loading

0 comments on commit 7be7e24

Please sign in to comment.