Socket
Socket
Sign inDemoInstall

@agile-ts/logger

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.0.6

dist/logger.d.ts

25

CHANGELOG.md
# @agile-ts/logger
## 0.0.6
### Patch Changes
- cef61b6: #### :rocket: New Feature
- `react`
- [#171](https://github.com/agile-ts/agile/pull/171) Add deps array to useAgile() hook ([@bennodev19](https://github.com/bennodev19))
- `core`, `event`, `react`, `vue`
- [#166](https://github.com/agile-ts/agile/pull/166) Shared Agile Instance ([@bennodev19](https://github.com/bennodev19))
#### :nail_care: Polish
- `api`, `core`, `event`, `logger`, `multieditor`, `react`, `utils`
- [#168](https://github.com/agile-ts/agile/pull/168) Performance optimization ([@bennodev19](https://github.com/bennodev19))
- `core`, `event`, `react`, `vue`
- [#166](https://github.com/agile-ts/agile/pull/166) Shared Agile Instance ([@bennodev19](https://github.com/bennodev19))
#### Committers: 1
- BennoDev ([@bennodev19](https://github.com/bennodev19))
- Updated dependencies [cef61b6]
- @agile-ts/utils@0.0.6
## 0.0.5

@@ -4,0 +29,0 @@

173

dist/index.d.ts

@@ -1,167 +0,14 @@

export declare class Logger {
key?: LoggerKey;
isActive: boolean;
config: LoggerConfigInterface;
allowedTags: string[];
loggerCategories: {
[key: string]: LoggerCategoryInterface;
};
watchers: {
[key: string]: LoggerWatcherConfigInterface;
};
/**
* @public
* Logger - Handy Class for handling console.logs
*/
constructor(config?: LoggerConfig);
/**
* @public
* Adds Conditions to Logs
*/
get if(): {
tag: (tags: string[]) => {
log: (...data: any[]) => void;
debug: (...data: any[]) => void;
info: (...data: any[]) => void;
success: (...data: any[]) => void;
warn: (...data: any[]) => void;
error: (...data: any[]) => void;
trace: (...data: any[]) => void;
table: (...data: any[]) => void;
};
};
/**
* @public
* Default Levels of Logger
*/
static get level(): {
TRACE: number;
DEBUG: number;
LOG: number;
TABLE: number;
INFO: number;
SUCCESS: number;
WARN: number;
ERROR: number;
};
/**
* @internal
* Adds Default Logger Categories
*/
private addDefaultLoggerCategories;
/**
* @internal
* Only executes following 'command' if all given tags are included in allowedTags
* @param tags - Tags
*/
private tag;
log(...data: any[]): void;
debug(...data: any[]): void;
info(...data: any[]): void;
success(...data: any[]): void;
warn(...data: any[]): void;
error(...data: any[]): void;
trace(...data: any[]): void;
table(...data: any[]): void;
custom(loggerCategory: string, ...data: any[]): void;
/**
* @internal
* Logs data in Console
* @param data - Data
* @param loggerCategoryKey - Key/Name of Logger Category
* @param consoleLogType - console[consoleLogProperty]
*/
private invokeConsole;
/**
* @public
* Creates new Logger Category
* @param loggerCategory - Logger Category
*/
createLoggerCategory(loggerCategory: LoggerCategoryInterface): void;
/**
* @public
* Get Logger Category
* @param key - Key/Name of Logger Category
*/
getLoggerCategory(key: LoggerCategoryKey): LoggerCategoryInterface;
/**
* @public
* Watches Logger and detects Logs
* @param config - Config
* @return Key of Watcher Function
*/
watch(config: LoggerWatcherConfigInterface): string;
/**
* @public
* Watches Logger and detects Logs
* @param key - Key of Watcher Function
* @param config - Config
*/
watch(key: string, config: LoggerWatcherConfigInterface): this;
/**
* @public
* Removes Watcher at given Key
* @param key - Key of Watcher that gets removed
*/
removeWatcher(key: string): this;
/**
* @public
* Assigns new Level to Logger
* NOTE: Default Levels can be found in 'Logger.level.x'
* @param level - Level
*/
setLevel(level: number): this;
}
export declare type LoggerCategoryKey = string | number;
export declare type LoggerKey = string | number;
import { CreateLoggerConfigInterface, Logger } from './logger';
/**
* @param key - Key/Name of Logger Category
* @param customStyle - Css Styles that get applied to the Logs
* @param prefix - Prefix that gets written before each Log of this Category
* @param level - Until which Level this Logger Category gets logged
* Shared Agile Logger.
*/
export interface LoggerCategoryInterface {
key: LoggerCategoryKey;
customStyle?: string;
prefix?: string;
level: number;
}
declare let sharedAgileLogger: Logger;
/**
* @param prefix - Prefix that gets written before each log of this Logger
* @param canUseCustomStyles - If custom Styles can be applied to the Logs
* @param level - Handles which Logger Categories can be Logged
* @param timestamp - Timestamp that ges written before each log of this Logger
* Assigns the specified configuration object to the shared Agile Logger.
*
* @param config - Configuration object
*/
export interface LoggerConfigInterface {
prefix: string;
canUseCustomStyles: boolean;
level: number;
timestamp: boolean;
}
/**
* @param prefix - Prefix that gets written before each log of this Logger
* @param allowedTags - Only Logs that, contains the allowed Tags or have no Tag get logged
* @param canUseCustomStyles - If custom Styles can be applied to the Logs
* @param active - If Logger is active
* @param level - Handles which Logger Categories can be Logged
* @param timestamp - Timestamp that ges written before each log of this Logger
*/
export interface CreateLoggerConfigInterface {
prefix?: string;
allowedTags?: LoggerKey[];
canUseCustomStyles?: boolean;
active?: boolean;
level?: number;
timestamp?: boolean;
}
export declare type LoggerConfig = CreateLoggerConfigInterface | ((logger: Logger) => CreateLoggerConfigInterface);
export declare type ConsoleLogType = 'log' | 'warn' | 'error' | 'trace' | 'table' | 'info' | 'debug';
export declare type LoggerWatcherCallback = (loggerCategory: LoggerCategoryInterface, data: any[]) => void;
/**
* @param callback - Callback Function that gets called if something gets Logged
* @param level - At which level the watcher is called
*/
export interface LoggerWatcherConfigInterface {
callback: LoggerWatcherCallback;
level?: number;
}
declare function assignSharedAgileLoggerConfig(config?: CreateLoggerConfigInterface): Logger;
export { sharedAgileLogger, assignSharedAgileLoggerConfig };
export * from './logger';
export default Logger;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const utils_1 = require("@agile-ts/utils");
class Logger {
constructor(config = {}) {
this.allowedTags = [];
this.loggerCategories = {};
this.watchers = {};
let _config = typeof config === 'function' ? config(this) : config;
_config = utils_1.defineConfig(_config, {
prefix: '',
allowedTags: [],
canUseCustomStyles: true,
active: true,
level: 0,
timestamp: false,
});
this.isActive = _config.active;
this.allowedTags = _config.allowedTags;
this.config = {
timestamp: _config.timestamp,
prefix: _config.prefix,
canUseCustomStyles: _config.canUseCustomStyles,
level: _config.level,
};
this.addDefaultLoggerCategories();
}
get if() {
return {
tag: (tags) => this.tag(tags),
};
}
static get level() {
return {
TRACE: 1,
DEBUG: 2,
LOG: 5,
TABLE: 5,
INFO: 10,
SUCCESS: 15,
WARN: 20,
ERROR: 50,
};
}
addDefaultLoggerCategories() {
this.createLoggerCategory({
key: 'log',
level: Logger.level.LOG,
});
this.createLoggerCategory({
key: 'debug',
customStyle: 'color: #656565;',
prefix: 'Debug',
level: Logger.level.DEBUG,
});
this.createLoggerCategory({
key: 'info',
customStyle: 'color: #6c69a0;',
prefix: 'Info',
level: Logger.level.INFO,
});
this.createLoggerCategory({
key: 'success',
customStyle: 'color: #00b300;',
prefix: 'Success',
level: Logger.level.SUCCESS,
});
this.createLoggerCategory({
key: 'warn',
prefix: 'Warn',
level: Logger.level.WARN,
});
this.createLoggerCategory({
key: 'error',
prefix: 'Error',
level: Logger.level.ERROR,
});
this.createLoggerCategory({
key: 'trace',
prefix: 'Trace',
level: Logger.level.TRACE,
});
this.createLoggerCategory({
key: 'table',
level: Logger.level.TABLE,
});
}
tag(tags) {
if (utils_1.includesArray(this.allowedTags, tags)) {
return {
log: (...data) => this.log(...data),
debug: (...data) => this.debug(...data),
info: (...data) => this.info(...data),
success: (...data) => this.success(...data),
warn: (...data) => this.warn(...data),
error: (...data) => this.error(...data),
trace: (...data) => this.trace(...data),
table: (...data) => this.table(...data),
};
}
return {
log: () => {
},
debug: () => {
},
info: () => {
},
success: () => {
},
warn: () => {
},
error: () => {
},
trace: () => {
},
table: () => {
},
};
}
log(...data) {
this.invokeConsole(data, 'log', 'log');
}
debug(...data) {
this.invokeConsole(data, 'debug', typeof console.debug !== 'undefined' ? 'debug' : 'log');
}
info(...data) {
this.invokeConsole(data, 'info', typeof console.info !== 'undefined' ? 'info' : 'log');
}
success(...data) {
this.invokeConsole(data, 'success', 'log');
}
warn(...data) {
this.invokeConsole(data, 'warn', typeof console.warn !== 'undefined' ? 'warn' : 'log');
}
error(...data) {
this.invokeConsole(data, 'error', typeof console.error !== 'undefined' ? 'error' : 'log');
}
trace(...data) {
this.invokeConsole(data, 'trace', typeof console.trace !== 'undefined' ? 'trace' : 'log');
}
table(...data) {
this.invokeConsole(data, 'table', typeof console.table !== 'undefined' ? 'table' : 'log');
}
custom(loggerCategory, ...data) {
this.invokeConsole(data, loggerCategory, 'log');
}
invokeConsole(data, loggerCategoryKey, consoleLogType) {
const loggerCategory = this.getLoggerCategory(loggerCategoryKey);
if (!this.isActive || loggerCategory.level < this.config.level)
return;
const buildPrefix = () => {
let prefix = '';
if (this.config.timestamp)
prefix = prefix.concat(`[${Date.now().toString()}] `);
if (this.config.prefix)
prefix = prefix.concat(this.config.prefix);
if (loggerCategory.prefix)
prefix = prefix.concat(' ' + loggerCategory.prefix);
if (this.config.prefix || loggerCategory.prefix)
prefix = prefix.concat(':');
return prefix;
};
if (typeof data[0] === 'string')
data[0] = buildPrefix().concat(' ').concat(data[0]);
else
data.unshift(buildPrefix());
for (const key in this.watchers) {
const watcher = this.watchers[key];
if (loggerCategory.level >= (watcher.level || 0)) {
watcher.callback(loggerCategory, data);
}
}
if (this.config.canUseCustomStyles && loggerCategory.customStyle) {
const newLogs = [];
let hasStyledString = false;
for (const log of data) {
if (!hasStyledString && typeof log === 'string') {
newLogs.push(`%c${log}`);
newLogs.push(loggerCategory.customStyle);
hasStyledString = true;
}
else {
newLogs.push(log);
}
}
data = newLogs;
}
if (consoleLogType === 'table') {
if (typeof data[0] === 'string') {
console.log(data[0]);
console.table(data.filter((d) => typeof d !== 'string' && 'number'));
}
return;
}
console[consoleLogType](...data);
}
createLoggerCategory(loggerCategory) {
loggerCategory = utils_1.defineConfig(loggerCategory, {
prefix: '',
level: 0,
});
this.loggerCategories[loggerCategory.key] = loggerCategory;
}
getLoggerCategory(key) {
return this.loggerCategories[key];
}
watch(keyOrConfig, config) {
const generateKey = utils_1.isValidObject(keyOrConfig);
let _config;
let key;
if (generateKey) {
key = utils_1.generateId();
_config = keyOrConfig;
}
else {
key = keyOrConfig;
_config = config;
}
_config = utils_1.defineConfig(_config, {
level: 0,
});
if (!utils_1.isFunction(_config.callback)) {
console.error('Agile: A Watcher Callback Function has to be an function!');
return this;
}
if (this.watchers[key]) {
console.error(`Agile: Watcher Callback Function with the key/name ${key} already exists!`);
return this;
}
this.watchers[key] = _config;
return generateKey ? key : this;
}
removeWatcher(key) {
delete this.watchers[key];
return this;
}
setLevel(level) {
this.config.level = level;
return this;
}
exports.assignSharedAgileLoggerConfig = exports.sharedAgileLogger = void 0;
const logger_1 = require("./logger");
const defaultLogConfig = {
prefix: 'Agile',
active: true,
level: logger_1.Logger.level.WARN,
canUseCustomStyles: true,
allowedTags: ['runtime', 'storage', 'subscription', 'multieditor'],
};
let sharedAgileLogger = new logger_1.Logger(defaultLogConfig);
exports.sharedAgileLogger = sharedAgileLogger;
function assignSharedAgileLoggerConfig(config = {}) {
config = Object.assign(Object.assign({}, defaultLogConfig), config);
exports.sharedAgileLogger = sharedAgileLogger = new logger_1.Logger(config);
return sharedAgileLogger;
}
exports.Logger = Logger;
exports.assignSharedAgileLoggerConfig = assignSharedAgileLoggerConfig;
__exportStar(require("./logger"), exports);
exports.default = logger_1.Logger;
{
"name": "@agile-ts/logger",
"version": "0.0.5",
"version": "0.0.6",
"author": "BennoDev",

@@ -33,3 +33,3 @@ "license": "MIT",

"dependencies": {
"@agile-ts/utils": "^0.0.5"
"@agile-ts/utils": "^0.0.6"
},

@@ -36,0 +36,0 @@ "publishConfig": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc