Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils) add general logger #1712

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"utils/gear-hooks",
"utils/gear-ui",
"utils/vara-ui",
"utils/wallet-connect"
"utils/wallet-connect",
"utils/gear-logger"
],
"npmClient": "yarn",
"command": {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"utils/gear-hooks",
"utils/gear-ui",
"utils/vara-ui",
"utils/wallet-connect"
"utils/wallet-connect",
"utils/gear-logger"
],
"scripts": {
"clean": "lerna run clean --parallel && lerna clean -y && rm -rf node_modules",
Expand Down
1 change: 1 addition & 0 deletions utils/gear-logger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# gear-logger
26 changes: 26 additions & 0 deletions utils/gear-logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@gear-js/logger",
"version": "0.1.0",
"author": "Gear Technologies",
"bugs": {
"url": "https://github.com/gear-tech/gear-js/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gear-tech/gear-js.git"
},
"keywords": [
"gear",
"gear-js"
],
"scripts": {
"build": "rm -rf dist && tsc"
},
"dependencies": {
"winston": "3.7.2"
},
"devDependencies": {
"typescript": "4.7.4"
},
"type": "module"
}
2 changes: 2 additions & 0 deletions utils/gear-logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { logger } from './logger';
export { logger };
15 changes: 15 additions & 0 deletions utils/gear-logger/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createLogger, format, transports } from 'winston';

const TIMESTAMP_FORMAT = 'YY-MM-DD HH:mm:ss';

export const logger = createLogger({
format: format.combine(
format.timestamp({ format: TIMESTAMP_FORMAT }),
format(({ timestamp, level, message, ...rest }) => {
return { ts: timestamp, level, message, ...rest };
})(),
format.json({ bigint: true, deterministic: false }),
),
transports: [new transports.Console()],
exitOnError: false,
});
6 changes: 6 additions & 0 deletions utils/gear-logger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we either need types or don't need typescript at all

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exact types do you think we need? Because winston comes with own types installed.

"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
}
}
29 changes: 29 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,15 @@ __metadata:
languageName: unknown
linkType: soft

"@gear-js/logger@workspace:utils/gear-logger":
version: 0.0.0-use.local
resolution: "@gear-js/logger@workspace:utils/gear-logger"
dependencies:
typescript: "npm:4.7.4"
winston: "npm:3.7.2"
languageName: unknown
linkType: soft

"@gear-js/react-hooks@npm:*, @gear-js/react-hooks@workspace:utils/gear-hooks":
version: 0.0.0-use.local
resolution: "@gear-js/react-hooks@workspace:utils/gear-hooks"
Expand Down Expand Up @@ -24697,6 +24706,16 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:4.7.4":
version: 4.7.4
resolution: "typescript@npm:4.7.4"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/8c1c4007b6ce5b24c49f0e89173ab9e82687cc6ae54418d1140bb63b82d6598d085ac0f993fe3d3d1fbf87a2c76f1f81d394dc76315bc72c7a9f8561c5d8d205
languageName: node
linkType: hard

"typescript@npm:5.4.5":
version: 5.4.5
resolution: "typescript@npm:5.4.5"
Expand Down Expand Up @@ -24727,6 +24746,16 @@ __metadata:
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A4.7.4#optional!builtin<compat/typescript>":
version: 4.7.4
resolution: "typescript@patch:typescript@npm%3A4.7.4#optional!builtin<compat/typescript>::version=4.7.4&hash=65a307"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/2eb6e31b04fabec84a4d07b5d567deb5ef0a2971d89d9adb16895f148f7d8508adfb12074abc2efc6966805d3664e68ab67925060e5b0ebd8da616db4b151906
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>":
version: 5.4.5
resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>::version=5.4.5&hash=5adc0c"
Expand Down
Loading