Merge branch 'master' into write_enhancement

This commit is contained in:
Jörg Breitbart
2019-09-13 13:30:10 +02:00
3 changed files with 26 additions and 12 deletions
+1 -2
View File
@@ -121,8 +121,7 @@ jobs:
displayName: 'Install Yarn' displayName: 'Install Yarn'
- script: | - script: |
yarn yarn
BUILD_DIR=dist npm run build
displayName: 'Install dependencies and build' displayName: 'Install dependencies and build'
- script: | - script: |
NPM_AUTH_TOKEN="$(NPM_AUTH_TOKEN)" node ./bin/publish.js NPM_AUTH_TOKEN="$(NPM_AUTH_TOKEN)" node ./bin/publish.js
displayName: 'Publish to npm' displayName: 'Package and publish to npm'
+1 -1
View File
@@ -54,7 +54,7 @@ export class CoreService implements ICoreService {
} }
// Fire onData API // Fire onData API
this._logService.debug('sending data', data); this._logService.debug(`sending data "${data}"`, () => data.split('').map(e => e.charCodeAt(0)));
this._onData.fire(data); this._onData.fire(data);
} }
} }
+24 -9
View File
@@ -5,12 +5,14 @@
import { ILogService, IOptionsService } from 'common/services/Services'; import { ILogService, IOptionsService } from 'common/services/Services';
type LogType = (message?: any, ...optionalParams: any[]) => void;
interface IConsole { interface IConsole {
log(message?: any, ...optionalParams: any[]): void; log: LogType;
error(message?: any, ...optionalParams: any[]): void; error: LogType;
info(message?: any, ...optionalParams: any[]): void; info: LogType;
trace(message?: any, ...optionalParams: any[]): void; trace: LogType;
warn(message?: any, ...optionalParams: any[]): void; warn: LogType;
} }
// console is available on both node.js and browser contexts but the common // console is available on both node.js and browser contexts but the common
@@ -56,27 +58,40 @@ export class LogService implements ILogService {
this._logLevel = optionsKeyToLogLevel[this._optionsService.options.logLevel]; this._logLevel = optionsKeyToLogLevel[this._optionsService.options.logLevel];
} }
private _evalLazyOptionalParams(optionalParams: any[]): void {
for (let i = 0; i < optionalParams.length; i++) {
if (typeof optionalParams[i] === 'function') {
optionalParams[i] = optionalParams[i]();
}
}
}
private _log(type: LogType, message: string, optionalParams: any[]): void {
this._evalLazyOptionalParams(optionalParams);
type.call(console, LOG_PREFIX + message, ...optionalParams);
}
debug(message: string, ...optionalParams: any[]): void { debug(message: string, ...optionalParams: any[]): void {
if (this._logLevel <= LogLevel.DEBUG) { if (this._logLevel <= LogLevel.DEBUG) {
console.log.call(console, LOG_PREFIX + message, ...optionalParams); this._log(console.log, message, optionalParams);
} }
} }
info(message: string, ...optionalParams: any[]): void { info(message: string, ...optionalParams: any[]): void {
if (this._logLevel <= LogLevel.INFO) { if (this._logLevel <= LogLevel.INFO) {
console.info.call(console, LOG_PREFIX + message, ...optionalParams); this._log(console.info, message, optionalParams);
} }
} }
warn(message: string, ...optionalParams: any[]): void { warn(message: string, ...optionalParams: any[]): void {
if (this._logLevel <= LogLevel.WARN) { if (this._logLevel <= LogLevel.WARN) {
console.warn.call(console, LOG_PREFIX + message, ...optionalParams); this._log(console.warn, message, optionalParams);
} }
} }
error(message: string, ...optionalParams: any[]): void { error(message: string, ...optionalParams: any[]): void {
if (this._logLevel <= LogLevel.ERROR) { if (this._logLevel <= LogLevel.ERROR) {
console.error.call(console, LOG_PREFIX + message, ...optionalParams); this._log(console.error, message, optionalParams);
} }
} }
} }