feat(ci): Add GitHub Actions workflows for CI/CD
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/logcontext',
|
||||
version: '2.0.0',
|
||||
description: 'enrich logs with context'
|
||||
name: '@push.rocks/smartcontext',
|
||||
version: '2.1.0',
|
||||
description: 'A module providing advanced asynchronous context management to enrich logs with context and manage scope effectively in Node.js applications.'
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
export * from './logcontext.classes.logger.js';
|
||||
export * from './logcontext.classes.asynccontext.js';
|
||||
|
13
ts/logcontext.classes.asynccontext.ts
Normal file
13
ts/logcontext.classes.asynccontext.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import * as plugins from './logcontext.plugins.js';
|
||||
import { AsyncStore } from './logcontext.classes.asyncstore.js';
|
||||
|
||||
export class AsyncContext {
|
||||
private context = new plugins.simpleAsyncContext.AsyncContext.Variable<AsyncStore>();
|
||||
public store = new AsyncStore();
|
||||
public runScoped(functionArg: (storeArg: AsyncStore) => Promise<void>) {
|
||||
this.context.run(this.store, async () => {
|
||||
const childStore = new AsyncStore(this.store);
|
||||
functionArg(childStore)
|
||||
});
|
||||
}
|
||||
}
|
50
ts/logcontext.classes.asyncstore.ts
Normal file
50
ts/logcontext.classes.asyncstore.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import * as plugins from './logcontext.plugins.js';
|
||||
|
||||
export class AsyncStore {
|
||||
private parentStore?: AsyncStore;
|
||||
private deletedKeys: string[] = [];
|
||||
private dataObject: {[key: string]: any} = {};
|
||||
|
||||
constructor(parentStore?: AsyncStore) {
|
||||
this.parentStore = parentStore;
|
||||
}
|
||||
|
||||
private cleanUp() {
|
||||
for (const key of this.deletedKeys) {
|
||||
if (this.parentStore && this.parentStore.get(key)) {
|
||||
// ok still valid
|
||||
} else {
|
||||
delete this.deletedKeys[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public add(keyArg: string, objectArg: any) {
|
||||
this.cleanUp();
|
||||
if (this.deletedKeys.includes(keyArg)) {
|
||||
this.deletedKeys = this.deletedKeys.filter((key) => key !== keyArg);
|
||||
}
|
||||
this.dataObject[keyArg] = objectArg;
|
||||
}
|
||||
|
||||
public delete(paramName: string) {
|
||||
this.cleanUp();
|
||||
if (this.parentStore.get(paramName)) {
|
||||
this.deletedKeys.push(paramName);
|
||||
}
|
||||
delete this.dataObject[paramName];
|
||||
}
|
||||
|
||||
public get(paramName: string) {
|
||||
this.cleanUp();
|
||||
if (this.deletedKeys.includes(paramName)) {
|
||||
return undefined;
|
||||
}
|
||||
return this.dataObject[paramName] || this.parentStore?.get(paramName);
|
||||
}
|
||||
|
||||
public getAll() {
|
||||
this.cleanUp();
|
||||
return {...this.dataObject, ...(this.parentStore?.getAll() || {})};
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
import * as plugins from './logcontext.plugins.js';
|
||||
import { LogMap } from './logcontext.classes.logmap.js';
|
||||
|
||||
export class Logger {
|
||||
public namespaceString: string;
|
||||
smartcls: plugins.smartcls.SmartCls;
|
||||
public logmap: LogMap;
|
||||
public thirdPartyLogger: any;
|
||||
settings = {
|
||||
enableScope: () => {
|
||||
this.settingsParams.scope = true;
|
||||
},
|
||||
disableScope: () => {
|
||||
this.settingsParams.scope = false;
|
||||
},
|
||||
enableAddData: () => {
|
||||
this.settingsParams.addData = true;
|
||||
},
|
||||
disableAddData: () => {
|
||||
this.settingsParams.addData = false;
|
||||
},
|
||||
};
|
||||
private settingsParams: { scope: boolean; addData: boolean } = {
|
||||
scope: true,
|
||||
addData: true,
|
||||
};
|
||||
|
||||
constructor(namespaceArg: string = plugins.smartunique.shortId()) {
|
||||
this.namespaceString = namespaceArg;
|
||||
this.smartcls = new plugins.smartcls.SmartCls();
|
||||
this.logmap = new LogMap(this.smartcls);
|
||||
}
|
||||
|
||||
addData(paramNameArg: string, dataArg: any) {
|
||||
if (this.settingsParams.addData) {
|
||||
this.logmap.addData(paramNameArg, dataArg);
|
||||
}
|
||||
}
|
||||
|
||||
addThirdPartyLogger(thirdPartyLoggerArg: any) {
|
||||
this.thirdPartyLogger = thirdPartyLoggerArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* debug
|
||||
* @param logMessageArg
|
||||
*/
|
||||
debug(logMessageArg: string) {
|
||||
this.routeLog('debug', logMessageArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* log
|
||||
* @param logMessageArg
|
||||
*/
|
||||
log(logMessageArg: string) {
|
||||
this.routeLog('log', logMessageArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* info
|
||||
* @param logMessageArg
|
||||
*/
|
||||
info(logMessageArg: string) {
|
||||
this.routeLog('info', logMessageArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* error
|
||||
* @param logMessageArg
|
||||
* @param args
|
||||
*/
|
||||
error(logMessageArg: string, ...args: any) {
|
||||
this.routeLog('error', logMessageArg, ...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* warn
|
||||
* @param logMessageArg
|
||||
* @param args
|
||||
*/
|
||||
warn(logMessageArg: string, ...args: any) {
|
||||
this.routeLog('warn', logMessageArg, ...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* fatal
|
||||
* @param logMessageArg
|
||||
* @param args
|
||||
*/
|
||||
fatal(logMessageArg: string, ...args: any) {
|
||||
this.routeLog('fatal', logMessageArg, ...args);
|
||||
}
|
||||
|
||||
// creates a new async scope
|
||||
scope(funcArg: any) {
|
||||
// create node continuation scope
|
||||
if (this.settingsParams.scope) {
|
||||
this.smartcls.run(funcArg);
|
||||
} else {
|
||||
funcArg();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* routes the log according to whats available in the environment
|
||||
* @param {string} logMethod
|
||||
* @param {any} messageArg
|
||||
* @param {any[]} ...args
|
||||
*/
|
||||
private routeLog(logMethod: string, messageArg: string, ...args: any) {
|
||||
const logObject = {
|
||||
message: messageArg,
|
||||
type: logMethod,
|
||||
logContext: this.logmap.getAllData(),
|
||||
};
|
||||
if (this.thirdPartyLogger && this.thirdPartyLogger[logMethod]) {
|
||||
this.thirdPartyLogger[logMethod](logObject, ...args);
|
||||
} else {
|
||||
console.log(logObject);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
import * as plugins from './logcontext.plugins.js';
|
||||
|
||||
export class LogMap {
|
||||
smartcls: plugins.smartcls.SmartCls;
|
||||
paramMap = new plugins.lik.Stringmap();
|
||||
|
||||
constructor(clsNamespaceArg: plugins.smartcls.SmartCls) {
|
||||
this.smartcls = clsNamespaceArg;
|
||||
}
|
||||
|
||||
addData(paramName: string, logData: any) {
|
||||
this.paramMap.addString(paramName);
|
||||
this.smartcls.set(paramName, logData);
|
||||
}
|
||||
|
||||
deleteData(paramName: string) {
|
||||
this.smartcls.set(paramName, null);
|
||||
}
|
||||
|
||||
getData(paramName: string) {
|
||||
return this.smartcls.get(paramName);
|
||||
}
|
||||
|
||||
getAllData() {
|
||||
const returnObject: any = {};
|
||||
for (const stringArg of this.paramMap.getStringArray()) {
|
||||
returnObject[stringArg] = this.smartcls.get(stringArg);
|
||||
}
|
||||
return returnObject;
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
// native scope
|
||||
import { AsyncLocalStorage } from 'async_hooks';
|
||||
|
||||
export { AsyncLocalStorage };
|
||||
|
||||
// pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartcls from '@pushrocks/smartcls';
|
||||
import * as smartunique from '@pushrocks/smartunique';
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartunique from '@push.rocks/smartunique';
|
||||
|
||||
export { lik, smartcls, smartunique };
|
||||
export { lik, smartunique };
|
||||
|
||||
// third party scope
|
||||
import simpleAsyncContext from 'simple-async-context';
|
||||
|
||||
export { simpleAsyncContext };
|
Reference in New Issue
Block a user