Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@alwatr/logger

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alwatr/logger - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0

67

CHANGELOG.md

@@ -6,13 +6,15 @@ # Change Log

# [0.11.0](https://github.com/AliMD/alwatr/compare/v0.10.1...v0.11.0) (2022-04-16)
# [0.12.0](https://github.com/AliMD/alwatr/compare/v0.11.0...v0.12.0) (2022-07-22)
**Note:** Version bump only for package @alwatr/logger
### Bug Fixes
* **logger:** refactor behavior of force ([7d9307b](https://github.com/AliMD/alwatr/commit/7d9307bb78523f3dae17b3bd80fa2fb47c90975f))
### Features
# [0.10.0](https://github.com/AliMD/alwatr/compare/v0.9.0...v0.10.0) (2022-04-02)
* **logger:** compatible with node.js ([7ee8b6d](https://github.com/AliMD/alwatr/commit/7ee8b6de3143e39c300345dec6864c9c56a4aae7))
* **logger:** node coloring support ([2b4aab6](https://github.com/AliMD/alwatr/commit/2b4aab655bc0707761587a7439de98bbd4ad0e08))
**Note:** Version bump only for package @alwatr/logger

@@ -22,10 +24,13 @@

# [0.11.0](https://github.com/AliMD/alwatr/compare/v0.10.1...v0.11.0) (2022-04-16)
# [0.9.0](https://github.com/AliMD/alwatr/compare/v0.8.0...v0.9.0) (2022-03-22)
**Note:** Version bump only for package @alwatr/logger
# [0.10.0](https://github.com/AliMD/alwatr/compare/v0.9.0...v0.10.0) (2022-04-02)
**Note:** Version bump only for package @alwatr/logger
# [0.9.0](https://github.com/AliMD/alwatr/compare/v0.8.0...v0.9.0) (2022-03-22)
**Note:** Version bump only for package @alwatr/logger

@@ -36,17 +41,8 @@ # [0.8.0](https://github.com/AliMD/alwatr/compare/v0.7.2...v0.8.0) (2022-03-14)

## [0.7.2](https://github.com/AliMD/alwatr/compare/v0.7.1...v0.7.2) (2022-03-12)
### Features
* **logger:** add debug and improve documents ([8f83d29](https://github.com/AliMD/alwatr/commit/8f83d2956e521f016fe530322f657c343f1a0b80))
- **logger:** add debug and improve documents ([8f83d29](https://github.com/AliMD/alwatr/commit/8f83d2956e521f016fe530322f657c343f1a0b80))
# [0.7.0](https://github.com/AliMD/alwatr/compare/v0.6.1...v0.7.0) (2022-03-12)

@@ -56,18 +52,9 @@

# [0.6.0](https://github.com/AliMD/alwatr/compare/v0.5.0...v0.6.0) (2022-03-11)
### Bug Fixes
* alalwatr ([898aa6e](https://github.com/AliMD/alwatr/commit/898aa6ed0888eab9265c83b96a50f1b8c216d143))
* **packages:** duplicate alwatr keyword ([77d4aa2](https://github.com/AliMD/alwatr/commit/77d4aa2105ad47515c3eee251fd6b8c281d0d1fc))
- alalwatr ([898aa6e](https://github.com/AliMD/alwatr/commit/898aa6ed0888eab9265c83b96a50f1b8c216d143))
- **packages:** duplicate alwatr keyword ([77d4aa2](https://github.com/AliMD/alwatr/commit/77d4aa2105ad47515c3eee251fd6b8c281d0d1fc))
# [0.5.0](https://github.com/AliMD/alwatr/compare/v0.4.0...v0.5.0) (2022-03-11)

@@ -77,3 +64,3 @@

* **logger:** refactor making logger object ([bc38018](https://github.com/AliMD/alwatr/commit/bc38018758540130df2f46c44521aea0a867bbe8))
- **logger:** refactor making logger object ([bc38018](https://github.com/AliMD/alwatr/commit/bc38018758540130df2f46c44521aea0a867bbe8))

@@ -84,8 +71,8 @@ # [0.4.0](https://github.com/AliMD/alwatr/compare/v0.3.0...v0.4.0) (2022-03-11)

* **logger:** types missing ([712363d](https://github.com/AliMD/alwatr/commit/712363d3cf77a712f8c801c4dc9d06d256dfc0e6))
- **logger:** types missing ([712363d](https://github.com/AliMD/alwatr/commit/712363d3cf77a712f8c801c4dc9d06d256dfc0e6))
### Features
* **logger:** add logProperty, logMethodFull ([8b0317d](https://github.com/AliMD/alwatr/commit/8b0317db88ed73604a27935a3a30cd5c31cb0804))
* **logger:** complete refactor the logger with new API and fix show correct line number ([7efe8cf](https://github.com/AliMD/alwatr/commit/7efe8cf0f566e148406f38fdd60fa3d747c9bc51))
- **logger:** add logProperty, logMethodFull ([8b0317d](https://github.com/AliMD/alwatr/commit/8b0317db88ed73604a27935a3a30cd5c31cb0804))
- **logger:** complete refactor the logger with new API and fix show correct line number ([7efe8cf](https://github.com/AliMD/alwatr/commit/7efe8cf0f566e148406f38fdd60fa3d747c9bc51))

@@ -100,3 +87,3 @@ # [0.3.0](https://github.com/AliMD/alwatr/compare/v0.2.1...v0.3.0) (2022-03-06)

* **logger:** alwatrRegisteredList name ([ff59133](https://github.com/AliMD/alwatr/commit/ff5913321c4eafa1ce53fdacebf8fb4f23bfe430))
- **logger:** alwatrRegisteredList name ([ff59133](https://github.com/AliMD/alwatr/commit/ff5913321c4eafa1ce53fdacebf8fb4f23bfe430))

@@ -115,3 +102,3 @@ # [0.2.0](https://github.com/AliMD/alwatr/compare/v0.1.2...v0.2.0) (2022-03-05)

* **packages:** add publish config to public ([9cb3710](https://github.com/AliMD/alwatr/commit/9cb37106b5a35d24d5195ff54232e5769ccc034e))
- **packages:** add publish config to public ([9cb3710](https://github.com/AliMD/alwatr/commit/9cb37106b5a35d24d5195ff54232e5769ccc034e))

@@ -122,11 +109,11 @@ # 0.1.0 (2022-03-02)

* **logger:** fix debug scope ([be62f14](https://github.com/AliMD/alwatr/commit/be62f142cbe3fe4d328e3fd9941ea7c2d640a23f))
* **logger:** fix logger debug scope ([e734d21](https://github.com/AliMD/alwatr/commit/e734d218db888ecec33a03dc805b98dd75543efd))
* tsconfig issues ([159adeb](https://github.com/AliMD/alwatr/commit/159adeb72de4626dc16f6657765605b0a2ddccb1))
- **logger:** fix debug scope ([be62f14](https://github.com/AliMD/alwatr/commit/be62f142cbe3fe4d328e3fd9941ea7c2d640a23f))
- **logger:** fix logger debug scope ([e734d21](https://github.com/AliMD/alwatr/commit/e734d218db888ecec33a03dc805b98dd75543efd))
- tsconfig issues ([159adeb](https://github.com/AliMD/alwatr/commit/159adeb72de4626dc16f6657765605b0a2ddccb1))
### Features
* **logger:** debug scope ([6e4190d](https://github.com/AliMD/alwatr/commit/6e4190dc9dafc28e3a7a481aa43622a23527993c))
* **logger:** debug scope logger package ([1a4baeb](https://github.com/AliMD/alwatr/commit/1a4baeb7a253ba66563dbcf06079242dabb9f246))
* **logger:** alwatr logger package ([711268e](https://github.com/AliMD/alwatr/commit/711268e17dea8ada9c901ef1e9d605b3212abd97))
* **logger:** alwatr meta structure ([feade73](https://github.com/AliMD/alwatr/commit/feade735a6f141db77b81d7791d8872d45c8bf7e))
- **logger:** debug scope ([6e4190d](https://github.com/AliMD/alwatr/commit/6e4190dc9dafc28e3a7a481aa43622a23527993c))
- **logger:** debug scope logger package ([1a4baeb](https://github.com/AliMD/alwatr/commit/1a4baeb7a253ba66563dbcf06079242dabb9f246))
- **logger:** alwatr logger package ([711268e](https://github.com/AliMD/alwatr/commit/711268e17dea8ada9c901ef1e9d605b3212abd97))
- **logger:** alwatr meta structure ([feade73](https://github.com/AliMD/alwatr/commit/feade735a6f141db77b81d7791d8872d45c8bf7e))
import type { Logger } from './type';
/**
* Define `window.Alwatr.registeredList`
* Define `globalThis.Alwatr.registeredList`
*/

@@ -17,3 +17,3 @@ export declare const alwatrRegisteredList: {

* - **color** is optional and automatically select from internal fancy color list.
* - **force** is optional and default to false.
* - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
*

@@ -27,3 +27,3 @@ * Example:

*/
export declare const createLogger: (scope: string, color?: string, force?: boolean) => Logger;
export declare const createLogger: (scope: string, color?: string, debug?: boolean) => Logger;
//# sourceMappingURL=logger.d.ts.map

@@ -1,8 +0,8 @@

var _a, _b, _c, _d;
var _a, _b, _c, _d, _e, _f, _g;
const isBrowser = typeof process === 'undefined';
/**
* Define `window.Alwatr.registeredList`
* Define `globalThis.Alwatr.registeredList`
*/
export const alwatrRegisteredList = ((_a = window.Alwatr) === null || _a === void 0 ? void 0 : _a.registeredList) || [];
(_b = window.Alwatr) !== null && _b !== void 0 ? _b : (window.Alwatr = {});
window.Alwatr.registeredList = alwatrRegisteredList;
export const alwatrRegisteredList = ((_a = globalThis.Alwatr) === null || _a === void 0 ? void 0 : _a.registeredList) || [];
(_b = globalThis.Alwatr) !== null && _b !== void 0 ? _b : (globalThis.Alwatr = { registeredList: alwatrRegisteredList });
alwatrRegisteredList.push({

@@ -16,19 +16,21 @@ name: '@alwatr/logger',

let colorIndex = 0;
const colorList = [
'#f05561',
'#35b997',
'#ee224a',
'#91c13e',
'#22af4b',
'#f0e995',
'#0fe995',
'#0f89ca',
'#08b9a5',
'#fee851',
'#ee573d',
'#f9df30',
'#1da2dc',
'#f05123',
'#ee2524',
];
const colorList = isBrowser ?
[
'#35b997',
'#f05561',
'#ee224a',
'#91c13e',
'#22af4b',
'#f0e995',
'#0fe995',
'#0f89ca',
'#08b9a5',
'#fee851',
'#ee573d',
'#f9df30',
'#1da2dc',
'#f05123',
'#ee2524',
] :
['0;36', '0;35', '0;34', '0;33', '0;32']; // red and white omitted
const getNextColor = () => {

@@ -42,4 +44,12 @@ const color = colorList[colorIndex];

};
const debugString = (_d = (_c = window.localStorage) === null || _c === void 0 ? void 0 : _c.getItem('ALWATR_LOG')) === null || _d === void 0 ? void 0 : _d.trim();
const getDebugState = (scope, force) => {
const debugString = isBrowser ?
(_d = (_c = globalThis.localStorage) === null || _c === void 0 ? void 0 : _c.getItem('ALWATR_DEBUG')) === null || _d === void 0 ? void 0 : _d.trim() :
(_g = (_f = (_e = globalThis.process) === null || _e === void 0 ? void 0 : _e.env) === null || _f === void 0 ? void 0 : _f.ALWATR_DEBUG) === null || _g === void 0 ? void 0 : _g.trim();
const getDebugState = (scope) => {
if (debugString == null &&
isBrowser === false &&
globalThis.process.env.NODE_ENV !== 'production') {
return true;
}
// prettier-ignore
if (debugString == null ||

@@ -49,4 +59,5 @@ debugString == '') {

}
if (force ||
debugString === scope ||
// prettier-ignore
if (debugString === scope ||
debugString === '*' ||
(debugString.indexOf('*') === 0 && // starts with `*` for example: `*alwatr*`

@@ -62,4 +73,4 @@ scope.indexOf(debugString.replaceAll('*', '')) !== -1) ||

export const style = {
scope: 'color: {{color}};',
reset: 'color: inherit;',
scope: isBrowser ? 'color: {{color}};' : '\x1b[{{color}}m',
reset: isBrowser ? 'color: inherit;' : '\x1b[0m',
};

@@ -70,3 +81,3 @@ /**

* - **color** is optional and automatically select from internal fancy color list.
* - **force** is optional and default to false.
* - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`
*

@@ -80,5 +91,4 @@ * Example:

*/
export const createLogger = (scope, color = getNextColor(), force = false) => {
export const createLogger = (scope, color = getNextColor(), debug = getDebugState(scope)) => {
scope = scope.trim();
const debug = getDebugState(scope, force);
const first = scope.charAt(0);

@@ -90,2 +100,3 @@ if (first !== '[' && first !== '{' && first !== '(' && first !== '<') {

const empty = () => { };
const keySection = isBrowser ? '%c%s%c' : '%s%s%s';
const styleScope = style.scope.replaceAll('{{color}}', color);

@@ -99,4 +110,8 @@ /**

scope,
accident: console.warn.bind(console, '%c%s%c.%s => Accident: "%s" (%s)!', styleScope, scope, style.reset),
error: console.error.bind(console, '%c%s%c.%s "%s" =>', styleScope, scope, style.reset),
accident: isBrowser ?
console.error.bind(console, '%c%s%c.%s "%s" => Accident: "%s" (%s)!', styleScope, scope, style.reset) :
console.error.bind(console, `${styleScope}⚠️ %s\x1b[33m.%s "%s" =>${style.reset}`, scope),
error: isBrowser ?
console.error.bind(console, '%c%s%c.%s "%s" =>', styleScope, scope, style.reset) :
console.error.bind(console, `${styleScope}❌ %s\x1b[31m.%s "%s" =>\x1b[0;2m`, scope),
};

@@ -117,10 +132,12 @@ if (!debug) {

...requiredItems,
logProperty: console.debug.bind(console, '%c%s%c.%s = %o;', styleScope, scope, style.reset),
logMethod: console.debug.bind(console, '%c%s%c.%s();', styleScope, scope, style.reset),
logMethodArgs: console.debug.bind(console, '%c%s%c.%s(%o);', styleScope, scope, style.reset),
logMethodFull: console.debug.bind(console, '%c%s%c.%s(%o); // %o', styleScope, scope, style.reset),
incident: console.trace.bind(console, '%c%s%c.%s() => Incident: "%s" (%s)!', styleScope, scope, style.reset),
logOther: console.debug.bind(console, '%c%s', styleScope, scope),
logProperty: console.debug.bind(console, keySection + '.%s = %o;', styleScope, scope, style.reset),
logMethod: console.debug.bind(console, keySection + '.%s();', styleScope, scope, style.reset),
logMethodArgs: console.debug.bind(console, keySection + '.%s(%o);', styleScope, scope, style.reset),
logMethodFull: console.debug.bind(console, keySection + '.%s(%o); // %o', styleScope, scope, style.reset),
incident: isBrowser ?
console.trace.bind(console, '%c%s%c.%s() => Incident: "%s" (%s)!', styleScope, scope, style.reset) :
console.log.bind(console, `${styleScope}🔸 %s${style.reset}.%s() => Incident: "%s" (%s)!\x1b[0;2m`, scope),
logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),
};
};
//# sourceMappingURL=logger.js.map
{
"name": "@alwatr/logger",
"version": "0.11.0",
"version": "0.12.0",
"description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",

@@ -28,5 +28,5 @@ "keywords": [

"url": "https://github.com/AliMD/alwatr",
"directory": "package/logger"
"directory": "packages/core/logger"
},
"homepage": "https://github.com/AliMD/alwatr/tree/main/package/logger#readme",
"homepage": "https://github.com/AliMD/alwatr/tree/main/packages/core/logger#readme",
"bugs": {

@@ -38,3 +38,3 @@ "url": "https://github.com/AliMD/alwatr/issues"

},
"gitHead": "7d734c552f37d65998f2f8bd57db7a64998dc9e4"
"gitHead": "2da92e22ea946abf6155122d0a28674dd4c0308b"
}

@@ -8,7 +8,7 @@ # @alwatr/logger

```ts
import { createLogger } from 'https://esm.run/@alwatr/logger';
import {createLogger} from 'https://esm.run/@alwatr/logger';
const logger = createLogger('demo');
function sayHello (name: string) {
function sayHello(name: string) {
logger.logMethodArgs('sayHello', {name});

@@ -26,3 +26,3 @@ }

```ts
window.localStorage?.setItem('ALWATR_LOG', '*');
window.localStorage?.setItem('ALWATR_DEBUG', '*');
```

@@ -33,3 +33,3 @@

```ts
window.localStorage?.setItem('ALWATR_LOG', 'scope_name');
window.localStorage?.setItem('ALWATR_DEBUG', 'scope_name');
```

@@ -40,3 +40,3 @@

```ts
window.localStorage?.setItem('ALWATR_LOG', '*alwatr*');
window.localStorage?.setItem('ALWATR_DEBUG', '*alwatr*');
```

@@ -51,3 +51,3 @@

- **color** is optional and automatically select from internal fancy color list.
- **force** is optional and default to false.
- **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`

@@ -63,11 +63,11 @@ Example:

Debug state for current scope base on localStorage `ALWATR_LOG` pattern.
Debug state for current scope base on localStorage `ALWATR_DEBUG` pattern.
### `logger.color: string`
Debug state for current scope base on localStorage `ALWATR_LOG` pattern.
Debug state for current scope base on localStorage `ALWATR_DEBUG` pattern.
### `logger.scope: string`
Debug state for current scope base on localStorage `ALWATR_LOG` pattern.
Debug state for current scope base on localStorage `ALWATR_DEBUG` pattern.

@@ -91,3 +91,3 @@ ### `logger.logProperty(property, value)`

```ts
function myMethod () {
function myMethod() {
logger.logMethod('myMethod');

@@ -104,3 +104,3 @@ }

```ts
function myMethod (a: number, b: number) {
function myMethod(a: number, b: number) {
logger.logMethodArgs('myMethod', {a, b});

@@ -117,3 +117,3 @@ }

```ts
function add (a: number, b: number): number {
function add(a: number, b: number): number {
const result = a + b;

@@ -142,3 +142,5 @@ logger.logMethodFull('add', {a, b}, result);

```ts
logger.accident('fetch', 'file_not_found', 'url requested return 404 not found', {url: '/test.json'});
logger.accident('fetch', 'file_not_found', 'url requested return 404 not found', {
url: '/test.json',
});
```

@@ -176,3 +178,4 @@

```ts
const failPromiseTest = (): Promise<never> => new Promise((_, reject) => reject(new Error('my_error_code')));
const failPromiseTest = (): Promise<never> =>
new Promise((_, reject) => reject(new Error('my_error_code')));
```

@@ -184,4 +187,5 @@

// Unhandled promise rejection (just log it)
failPromiseTest()
.catch((err) => logger.error('myMethod', (err as Error).message || 'error_code', (err as Error).stack || err));
failPromiseTest().catch((err) =>
logger.error('myMethod', (err as Error).message || 'error_code', (err as Error).stack || err)
);

@@ -192,6 +196,10 @@ // Handled promise rejection

} catch (err) {
logger.accident('myMethod', 'error_code', 'failPromiseTest failed!, ' + (err as Error).message,
(err as Error).stack || err);
logger.accident(
'myMethod',
'error_code',
'failPromiseTest failed!, ' + (err as Error).message,
(err as Error).stack || err
);
// do something to handle the error...
}
```

@@ -0,10 +1,10 @@

export interface GlobalAlwatr {
registeredList: Array<{
name: string;
version: string;
}>;
}
declare global {
interface Window {
Alwatr?: {
registeredList?: Array<{
name: string;
version: string;
}>;
};
}
var Alwatr: GlobalAlwatr;
var ALWATR_DEBUG: string | undefined;
/**

@@ -11,0 +11,0 @@ * @TODO: Make an issue to TS, WTF is this way! any better solution for more args in bind?!

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc