Skip to content

Commit

Permalink
fix(logger, nano-server): review latest PRs (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd authored Dec 20, 2022
2 parents 9faa772 + a0a006d commit a4b051e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions core/logger/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ export const createLogger = (scope: string, color?: string | null, debug?: boole
color,
scope,

incident: isBrowser
? console.log.bind(console, '%c%s%c.%s() Incident `%s` %s!', styleScope, scope, 'color: orange;')
: console.log.bind(console, `${styleScope}🚸\n%s${style.reset}.%s() Incident \`%s\` %s!${style.reset}`, scope),

accident: isBrowser
? console.warn.bind(console, '%c%s%c.%s() Accident `%s` %s!', styleScope, scope, style.reset)
: console.warn.bind(console, `${styleScope}⚠️\n%s\x1b[33m.%s() Accident \`%s\` %s!${style.reset}`, scope),
Expand All @@ -147,6 +143,7 @@ export const createLogger = (scope: string, color?: string | null, debug?: boole
logMethodArgs: empty,
logMethodFull: empty,
logOther: empty,
incident: empty,
};
}

Expand All @@ -163,5 +160,9 @@ export const createLogger = (scope: string, color?: string | null, debug?: boole
logMethodFull: console.debug.bind(console, keySection + '.%s(%o) => %o', styleScope, scope, style.reset),

logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),

incident: isBrowser
? console.log.bind(console, '%c%s%c.%s() Incident `%s` %s!', styleScope, scope, 'color: orange;')
: console.log.bind(console, `${styleScope}🚸\n%s${style.reset}.%s() Incident \`%s\` %s!${style.reset}`, scope),
};
};
5 changes: 3 additions & 2 deletions core/logger/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export interface AlwatrLogger {
logMethodFull(method: string, args: Record<string, unknown> | string | number | boolean, result: unknown): void;

/**
* `console.log` an event or expected accident. (not warn or error)
* `console.log` an event or expected accident.
* not warn or error just important information.
*
* Example:
*
Expand All @@ -107,7 +108,7 @@ export interface AlwatrLogger {
incident(method: string, code: string, desc: string, ...args: unknown[]): void;

/**
* `console.warn` an unexpected accident or error that you handled.
* `console.warn` an unexpected accident or error that you handled like warning.
*
* Example:
*
Expand Down
5 changes: 5 additions & 0 deletions core/nano-server/src/nano-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ export class AlwatrConnection {
* ```
*/
async getBody(): Promise<string | null> {
// method must be POST or PUT or PATCH
if (!(this.method === 'POST' || this.method === 'PUT' || this.method === 'PATCH')) {
return null;
}

let body = '';

this.incomingMessage.on('data', (chunk: unknown) => {
Expand Down
4 changes: 2 additions & 2 deletions core/storage-client/src/storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ alwatrRegisteredList.push({
*
* console.log('has \'alimd\': %o', await db.has('alimd'));
* console.log('keys: %o', await db.keys());
* console.log('getAll: %o', await db.getAll());
* console.log('getStorage: %o', await db.getStorage());
* console.log('delete: %o', await db.delete('alimd'));
* try {
* await db.delete('abcd');
Expand Down Expand Up @@ -102,7 +102,7 @@ export class AlwatrStorageClient<DocumentType extends AlwatrDocumentObject = Alw
* console.log('user_5000 id not found!');
* }
* else {
* console.err((err as Error)?.message || err);
* console.error((err as Error)?.message || err);
* }
* }
* ```
Expand Down

0 comments on commit a4b051e

Please sign in to comment.