diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..167ab9f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +yarn.lock \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..416bebf --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "tslog", + "version": "1.0.0", + "description": "Advanced TypeScript Logger", + "main": "src/index.ts", + "repository": "https://git.saluco.nl/strix/tslog.git", + "author": "Strix ", + "license": "MIT", + "dependencies": { + "@types/node": "^22.13.10", + "typescript": "^5.8.2" + } +} diff --git a/ILogItem.ts b/src/ILogItem.ts similarity index 100% rename from ILogItem.ts rename to src/ILogItem.ts diff --git a/LogLevel.ts b/src/LogLevel.ts similarity index 85% rename from LogLevel.ts rename to src/LogLevel.ts index 78f2f98..24d2ec4 100644 --- a/LogLevel.ts +++ b/src/LogLevel.ts @@ -4,5 +4,5 @@ export enum LogLevel { Info, Warn, Error, - Fatal + Critical } \ No newline at end of file diff --git a/common.ts b/src/common.ts similarity index 88% rename from common.ts rename to src/common.ts index 80eec6a..666c6ce 100644 --- a/common.ts +++ b/src/common.ts @@ -1,4 +1,4 @@ -import { Dispatch } from "./Dispatch"; +import { Dispatch } from "./dispatch/Dispatch"; import { ILogItem } from "./ILogItem"; import { LogLevel } from "./LogLevel"; @@ -15,7 +15,7 @@ export const LOGD = (...args) => CURRENT_DISPATCH.process({ timestamp: new Date( export const LOGI = (...args) => CURRENT_DISPATCH.process({ timestamp: new Date(), level: LogLevel.Info, data: args }); export const LOGW = (...args) => CURRENT_DISPATCH.process({ timestamp: new Date(), level: LogLevel.Warn, data: args }); export const LOGE = (...args) => CURRENT_DISPATCH.process({ timestamp: new Date(), level: LogLevel.Error, data: args }); -export const LOGF = (...args) => CURRENT_DISPATCH.process({ timestamp: new Date(), level: LogLevel.Fatal, data: args }); +export const LOGC = (...args) => CURRENT_DISPATCH.process({ timestamp: new Date(), level: LogLevel.Critical, data: args }); export const LOG = (item: Partial) => CURRENT_DISPATCH.process({ flags: item.flags ?? [], diff --git a/Dispatch.ts b/src/dispatch/Dispatch.ts similarity index 85% rename from Dispatch.ts rename to src/dispatch/Dispatch.ts index c507e83..2667d3a 100644 --- a/Dispatch.ts +++ b/src/dispatch/Dispatch.ts @@ -1,6 +1,6 @@ import { IDispatch, IDispatchConfig } from "./IDispatch"; -import { ILogItem } from "./ILogItem"; -import { LogLevel } from "./LogLevel"; +import { ILogItem } from "../ILogItem"; +import { LogLevel } from "../LogLevel"; export abstract class Dispatch implements IDispatch { children: IDispatch[] = []; diff --git a/FileDispatch.ts b/src/dispatch/FileDispatch.ts similarity index 86% rename from FileDispatch.ts rename to src/dispatch/FileDispatch.ts index 3624d93..2f72985 100644 --- a/FileDispatch.ts +++ b/src/dispatch/FileDispatch.ts @@ -1,8 +1,8 @@ import * as fs from "fs"; import { FormattedDispatch } from "./FormattedDispatch"; import { App } from "../App"; -import { ILogItem } from "./ILogItem"; -import { LOGE, LOGW } from "./common"; +import { ILogItem } from "../ILogItem"; +import { LOGE, LOGW } from "../common"; export class FileDispatch extends FormattedDispatch { path: string; diff --git a/FormattedDispatch.ts b/src/dispatch/FormattedDispatch.ts similarity index 94% rename from FormattedDispatch.ts rename to src/dispatch/FormattedDispatch.ts index 0fbafa5..ce0075c 100644 --- a/FormattedDispatch.ts +++ b/src/dispatch/FormattedDispatch.ts @@ -1,7 +1,7 @@ import { object } from "zod"; import { Dispatch } from "./Dispatch"; -import { ILogItem } from "./ILogItem"; -import { LogLevel } from "./LogLevel"; +import { ILogItem } from "../ILogItem"; +import { LogLevel } from "../LogLevel"; export class FormattedDispatch extends Dispatch { private formatString: string = "%t %l <%o>: %m"; diff --git a/IDispatch.ts b/src/dispatch/IDispatch.ts similarity index 85% rename from IDispatch.ts rename to src/dispatch/IDispatch.ts index a5f2e2e..a209ebd 100644 --- a/IDispatch.ts +++ b/src/dispatch/IDispatch.ts @@ -1,4 +1,4 @@ -import { ILogItem } from "./ILogItem"; +import { ILogItem } from "../ILogItem"; export interface IDispatchConfig {} diff --git a/SmartDispatch.ts b/src/dispatch/SmartDispatch.ts similarity index 92% rename from SmartDispatch.ts rename to src/dispatch/SmartDispatch.ts index d6bb4b6..ad553d9 100644 --- a/SmartDispatch.ts +++ b/src/dispatch/SmartDispatch.ts @@ -1,7 +1,7 @@ import { statSync } from "fs"; import { Dispatch } from "./Dispatch"; -import { ILogItem } from "./ILogItem"; -import { LogLevel } from "./LogLevel"; +import { ILogItem } from "../ILogItem"; +import { LogLevel } from "../LogLevel"; export class SmartDispatch extends Dispatch { process(item: ILogItem) { @@ -15,7 +15,7 @@ export class SmartDispatch extends Dispatch { while (!stack[i].includes("at SmartDispatch.process")) i++; let src = stack[i + 2].trim(); - let path = null; + let path: string | null = null; // now we need to format the src (at ...:..:.. or at App. ..., etc) if (src.includes("at ")) src = src.split("at ")[1]; diff --git a/StdoutDispatch.ts b/src/dispatch/StdoutDispatch.ts similarity index 74% rename from StdoutDispatch.ts rename to src/dispatch/StdoutDispatch.ts index 93f679a..4720310 100644 --- a/StdoutDispatch.ts +++ b/src/dispatch/StdoutDispatch.ts @@ -1,7 +1,7 @@ import { FormattedDispatch } from "./FormattedDispatch"; import { IDispatch } from "./IDispatch"; -import { ILogItem } from "./ILogItem"; -import { LogLevel } from "./LogLevel"; +import { ILogItem } from "../ILogItem"; +import { LogLevel } from "../LogLevel"; export class StdoutDispatch extends FormattedDispatch { output(item: ILogItem) { diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..1423be3 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,17 @@ +export { + LOG, + LOGT, + LOGD, + LOGI, + LOGW, + LOGE, + LOGC, + setDispatch +} from "./common"; + +export { Dispatch } from './dispatch/Dispatch'; +export { IDispatch } from './dispatch/IDispatch'; +export { FormattedDispatch } from './dispatch/FormattedDispatch'; +export { SmartDispatch } from './dispatch/SmartDispatch'; +export { FileDispatch } from './dispatch/FileDispatch'; +export { StdoutDispatch } from './dispatch/StdoutDispatch'; \ No newline at end of file