Moving class to library
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@nc/component-library",
|
||||
"name": "@nerdy-canuck/component-library",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/joeythelantern/Component-Library.git"
|
||||
@ -12,7 +12,7 @@
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rm -rf dist/ && npm run build:esm && npm run build:cjs",
|
||||
"build": "rm -rf dist/ && prettier --write src/ && npm run build:esm && npm run build:cjs",
|
||||
"build:esm": "tsc",
|
||||
"build:cjs": "tsc --module CommonJS --outDir dist/cjs"
|
||||
},
|
||||
|
@ -1 +1 @@
|
||||
export * from './useLogging';
|
||||
export * from './useLogging';
|
||||
|
@ -1,47 +1,8 @@
|
||||
import { useRef } from 'react';
|
||||
|
||||
class Logging {
|
||||
private namespace = 'Client';
|
||||
|
||||
constructor(namespace?: string) {
|
||||
if (namespace) this.namespace = namespace;
|
||||
}
|
||||
|
||||
public info = (message: any) => {
|
||||
if (typeof message === 'string') {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [INFO] ${message}`);
|
||||
} else {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [INFO]`, message);
|
||||
}
|
||||
};
|
||||
|
||||
public warn = (message: any) => {
|
||||
if (typeof message === 'string') {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [WARN] ${message}`);
|
||||
} else {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [WARN]`, message);
|
||||
}
|
||||
};
|
||||
|
||||
public error = (message: any) => {
|
||||
if (typeof message === 'string') {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [ERROR] ${message}`);
|
||||
} else {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [ERROR]`, message);
|
||||
}
|
||||
};
|
||||
|
||||
public getDate = () => {
|
||||
return new Date().toISOString();
|
||||
};
|
||||
|
||||
public setNamespace = (namespace: string) => {
|
||||
this.namespace = namespace;
|
||||
};
|
||||
}
|
||||
|
||||
export const useLogging = (namespace?: string): [Logging] => {
|
||||
const { current: logging } = useRef(new Logging(namespace));
|
||||
|
||||
return [logging];
|
||||
};
|
||||
import { useRef } from 'react';
|
||||
import Logging from '../library/Logging';
|
||||
|
||||
export const useLogging = (namespace?: string): [Logging] => {
|
||||
const { current: logging } = useRef(new Logging(namespace));
|
||||
|
||||
return [logging];
|
||||
};
|
||||
|
@ -1 +1 @@
|
||||
export * from './hooks';
|
||||
export * from './hooks';
|
||||
|
41
src/library/Logging.ts
Normal file
41
src/library/Logging.ts
Normal file
@ -0,0 +1,41 @@
|
||||
class Logging {
|
||||
private namespace = 'Default';
|
||||
|
||||
constructor(namespace?: string) {
|
||||
if (namespace) this.namespace = namespace;
|
||||
}
|
||||
|
||||
public info = (message: any) => {
|
||||
if (typeof message === 'string') {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [INFO] ${message}`);
|
||||
} else {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [INFO]`, message);
|
||||
}
|
||||
};
|
||||
|
||||
public warn = (message: any) => {
|
||||
if (typeof message === 'string') {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [WARN] ${message}`);
|
||||
} else {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [WARN]`, message);
|
||||
}
|
||||
};
|
||||
|
||||
public error = (message: any) => {
|
||||
if (typeof message === 'string') {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [ERROR] ${message}`);
|
||||
} else {
|
||||
console.log(`[${this.getDate()}] [${this.namespace}] [ERROR]`, message);
|
||||
}
|
||||
};
|
||||
|
||||
public getDate = () => {
|
||||
return new Date().toISOString();
|
||||
};
|
||||
|
||||
public setNamespace = (namespace: string) => {
|
||||
this.namespace = namespace;
|
||||
};
|
||||
}
|
||||
|
||||
export default Logging;
|
Reference in New Issue
Block a user