fix(structure): update smartlog compatibility

This commit is contained in:
Philipp Kunz 2018-07-05 23:40:33 +02:00
parent ca749d45b1
commit c978ada06c
8 changed files with 194 additions and 95 deletions

View File

@ -2,6 +2,7 @@
"npmci": {
"globalNpmTools": [
"npmts"
]
],
"npmAccessLevel": "public"
}
}

110
package-lock.json generated
View File

@ -14,6 +14,17 @@
"nan": "^2.9.2"
}
},
"@gitzone/tsrun": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@gitzone/tsrun/-/tsrun-1.1.1.tgz",
"integrity": "sha512-/hocNkbpcm65MrSdF3V28lBH2iNcZThtbvKuISdCVgKejQUugTe9uNzLn//UCuCbbXODSVmjMbbYU4nMksssUw==",
"dev": true,
"requires": {
"smartfile": "^4.2.28",
"ts-node": "^7.0.0",
"typescript": "^2.9.1"
}
},
"@types/chai": {
"version": "4.1.4",
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.4.tgz",
@ -53,9 +64,10 @@
"integrity": "sha512-iXYLa6olt4tnsCA+ZXeP6eEW3tk1SulWeYyP/yooWfAtXjozqXgtX4+XUtMuOCfYjKGz3F34++qUc3Q+TJuIIw=="
},
"@types/node": {
"version": "9.6.22",
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.22.tgz",
"integrity": "sha512-RIg9EkxzVMkNH0M4sLRngK23f5QiigJC0iODQmu4nopzstt8AjegYund3r82iMrd2BNCjcZVnklaItvKHaGfBA=="
"version": "10.5.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.1.tgz",
"integrity": "sha512-AFLl1IALIuyt6oK4AYZsgWVJ/5rnyzQWud7IebaZWWV3YmgtPZkQmYio9R5Ze/2pdd7XfqF5bP+hWS11mAKoOQ==",
"dev": true
},
"@types/vinyl": {
"version": "2.0.2",
@ -93,6 +105,12 @@
"sprintf-js": "~1.0.2"
}
},
"arrify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz",
"integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=",
"dev": true
},
"assertion-error": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
@ -166,6 +184,12 @@
"concat-map": "0.0.1"
}
},
"buffer-from": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.0.tgz",
"integrity": "sha512-c5mRlguI/Pe2dSZmpER62rSCu0ryKmWddzRYsuXc50U2/g8jMOulc31VZMa4mYx31U5xsmSOpDCgH88Vl9cDGQ==",
"dev": true
},
"chai": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz",
@ -302,6 +326,12 @@
"object-keys": "^1.0.8"
}
},
"diff": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
"dev": true
},
"early": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/early/-/early-2.1.1.tgz",
@ -548,6 +578,12 @@
"chalk": "^2.0.1"
}
},
"make-error": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.4.tgz",
"integrity": "sha512-0Dab5btKVPhibSalc9QGXb559ED7G7iLjFXBaj9Wq8O3vorueR5K5jaE3hkG6ZQINyhA/JgG6Qk4qdFQjsYV6g==",
"dev": true
},
"mimic-fn": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz",
@ -567,6 +603,23 @@
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true,
"requires": {
"minimist": "0.0.8"
},
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true
}
}
},
"nan": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
@ -750,6 +803,13 @@
"lodash": "^4.17.5",
"smartparam": "^1.0.2",
"smartq": "^1.1.6"
},
"dependencies": {
"@types/node": {
"version": "9.6.22",
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.22.tgz",
"integrity": "sha512-RIg9EkxzVMkNH0M4sLRngK23f5QiigJC0iODQmu4nopzstt8AjegYund3r82iMrd2BNCjcZVnklaItvKHaGfBA=="
}
}
},
"smartfile": {
@ -814,6 +874,22 @@
"smartq": "^1.1.1"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
},
"source-map-support": {
"version": "0.5.6",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.6.tgz",
"integrity": "sha512-N4KXEz7jcKqPf2b2vZF11lQIz9W5ZMuUcIOGj243lduidkf2fjkVKJS9vNxVWn3u/uxX38AcE8U9nnH9FPcq+g==",
"dev": true,
"requires": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
}
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
@ -886,12 +962,34 @@
"smartq": "^1.1.8"
}
},
"ts-node": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.0.tgz",
"integrity": "sha512-klJsfswHP0FuOLsvBZ/zzCfUvakOSSxds78mVeK7I+qP76YWtxf16hEZsp3U+b0kIo82R5UatGFeblYMqabb2Q==",
"dev": true,
"requires": {
"arrify": "^1.0.0",
"buffer-from": "^1.1.0",
"diff": "^3.1.0",
"make-error": "^1.1.1",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"source-map-support": "^0.5.6",
"yn": "^2.0.0"
}
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
"dev": true
},
"typescript": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
"dev": true
},
"typings-global": {
"version": "1.0.28",
"resolved": "https://registry.npmjs.org/typings-global/-/typings-global-1.0.28.tgz",
@ -966,6 +1064,12 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
},
"yn": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz",
"integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=",
"dev": true
}
}
}

View File

@ -1,19 +1,13 @@
{
"name": "@pushrocks/smartlog-destination-local",
"private": false,
"version": "7.0.0",
"description": "a smartlog destination targeting the local console",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)",
"testbrowser": "(npm test) && (node testbrowser.js)",
"gitsetup": "(git config push.followTags true)",
"push": "(git push origin master && git push origin release && git push --follow-tags)",
"reinstall": "(rm -r node_modules && npm install)",
"release": "(npm test) && (git pull origin master && npm version patch && git checkout release && git merge master && git checkout master && npm run push)",
"update": "(git checkout master && git pull origin master) && (npm install)",
"upgrade": "(npm run update) && (ncu upgradeAll && npm install)",
"build": "echo \"Not needed for now\""
"test": "(tsrun test/test.ts)",
"build": "(npmts)"
},
"repository": {
"type": "git",
@ -42,10 +36,10 @@
"smartq": "^1.1.6"
},
"devDependencies": {
"@gitzone/tsrun": "^1.1.1",
"@types/node": "^10.5.1",
"qenv": "^1.1.7",
"smartchai": "^2.0.1",
"smartdelay": "^1.0.4",
"tapbundle": "^2.0.0"
},
"private": true
"tapbundle": "^2.0.2"
}
}

View File

@ -4,46 +4,67 @@ import * as smartdelay from 'smartdelay';
import * as qenv from 'qenv';
let testQenv = new qenv.Qenv(process.cwd(), process.cwd() + '/.nogit');
import beautylog = require('../ts/index');
import smartlogDesinationLocal = require('../ts/index');
import { ILogContext } from 'smartlog-interfaces';
let testLogContext: ILogContext = {
company: 'Lossless GmbH',
companyunit: 'Lossless.Cloud',
containerName: 'gitlabci',
environment: 'staging',
runtime: 'node',
zone: 'shipzone'
}
let testLocalInstance: smartlogDesinationLocal.DestinationLocal;
tap.test('should create a valid instance of DestinationLocal', async () => {
testLocalInstance = new smartlogDesinationLocal.DestinationLocal()
expect(testLocalInstance).to.be.instanceof(smartlogDesinationLocal.DestinationLocal);
})
tap.test('.log(message) should print a blue Dir message', async () => {
beautylog.log('beautylog.log(), with normal logText, without logType');
testLocalInstance.handleLog({
logLevel: 'info',
logContext: testLogContext,
message: 'this is a info log message'
});
});
tap.test('.figlet should print nice fonts to console in yellow', async () => {
return beautylog.figlet('Async!', { font: 'Star Wars', color: 'orange' });
testLocalInstance.figlet('Async!', { font: 'Star Wars', color: 'orange' });
});
tap.test('.figletSync should print nice fonts to console in yellow', async () => {
beautylog.figletSync('Sync!', { font: 'Star Wars', color: 'blue' });
testLocalInstance.figletSync('Sync!', { font: 'Star Wars', color: 'blue' });
});
tap.test('.logReduced(message) should only log two messages', async () => {
beautylog.logReduced('Message 1');
beautylog.logReduced('Message 1');
beautylog.logReduced('Message 1');
beautylog.logReduced('Message 1');
beautylog.logReduced('Message 2');
beautylog.logReduced('Message 2');
testLocalInstance.logReduced('Message 1');
testLocalInstance.logReduced('Message 1');
testLocalInstance.logReduced('Message 1');
testLocalInstance.logReduced('Message 1');
testLocalInstance.logReduced('Message 2');
testLocalInstance.logReduced('Message 2');
});
tap.test('.newLine(number) create specified amount of new lines', async () => {
beautylog.newLine(1);
testLocalInstance.newLine(1);
});
tap.test('.ora(text,color) should display, update, and end a message', async () => {
beautylog.ora.start('This is a test text', 'green');
testLocalInstance.ora.start('This is a test text', 'green');
await smartdelay.delayFor(2000);
beautylog.ora.text('updated text!');
testLocalInstance.ora.text('updated text!');
await smartdelay.delayFor(2000);
await smartdelay.delayFor(2000);
beautylog.ora.endOk('Allright, ora works!');
testLocalInstance.ora.stop();
});
tap.test('.ora(text,color) should display an error message when ended with error', async () => {
beautylog.ora.start('This is another test text', 'green');
testLocalInstance.ora.start('This is another test text', 'green');
await smartdelay.delayFor(2000);
beautylog.ora.endError('Allright, ora displays an error!');
testLocalInstance.ora.stop();
});
tap.start();

View File

@ -2,8 +2,4 @@ import './sl.destlocal.console';
import * as plugins from './sl.destlocal.plugins';
// export classes
export { Ora } from './sl.destlocal.classes.ora';
// export methods
export { log, logReduced, newLine } from './beautylog.log';
export { figlet, figletSync } from './sl.destlocal.figlet';
export { DestinationLocal } from './sl.destlocal.classes.destinationlocal'

View File

@ -9,8 +9,13 @@ export interface IBeautyLogObject {
logString: string;
}
export class Beautylog implements ILogDestination {
export class DestinationLocal implements ILogDestination {
private oraInstance: Ora;
/**
* handles a log according to the smartlog standard
* @param logPackage
*/
handleLog(logPackage: ILogPackage) {
this.logToConsole(this.parseLog(logPackage.message));
}
@ -115,7 +120,13 @@ export class Beautylog implements ILogDestination {
console.log('unknown logType for "' + logString + '"');
break;
}
if (this.ora.state === 'running') {
this.ora.pause();
}
console.log(logString);
if (this.ora.state === 'paused') {
this.ora.start();
}
return true;
} catch (error) {
console.log(

View File

@ -1,17 +1,31 @@
import * as plugins from './sl.destlocal.plugins';
import { Beautylog } from './sl.destlocal.classes.beautylog';
import { DestinationLocal } from './sl.destlocal.classes.destinationlocal';
export class Ora {
beautylog: Beautylog;
state: string;
/**
* the destinationLocalInstance that ora talks to
*/
destinationLocalInstance: DestinationLocal;
/**
* the state of the current ora
*/
state: 'running' | 'stopped' | 'paused' = 'stopped';
/**
* the actual ora object
*/
private _oraObject;
constructor(beautylogInstanceArg: Beautylog = new Beautylog()) {
constructor(destinationLocalInstanceArg: DestinationLocal = new DestinationLocal()) {
this.destinationLocalInstance = destinationLocalInstanceArg;
this._oraObject = plugins.ora({
spinner: 'dots',
text: '',
color: 'blue'
});
}
text(textArg) {
this._oraObject.text = textArg;
}
@ -23,25 +37,25 @@ export class Ora {
if (colorArg) {
this._oraObject.color = colorArg;
}
this.state = 'running';
this._oraObject.start();
}
end() {
this._oraObject.stop();
this._oraObject.clear();
this.state = 'stopped';
}
endOk(textArg) {
this.end();
logNode('ok', textArg);
}
endError(textArg) {
this.end();
logNode('error', textArg);
}
pause() {
this._oraObject.stop();
this.state = 'paused';
}
/**
* stop is an alias for end
*/
stop() {
// alias for end
this.end();
}
}

View File

@ -1,42 +0,0 @@
// ======
// monkeypatch logging, so console logs are controled by beautylog
// ======
import plugins = require('./sl.destlocal.plugins');
import { activeOra, oraActive } from './sl.destlocal.classes.ora';
let nativeLog = console.log;
let nativeError = console.error;
/**
* routes the console to got through beautylog, so beautylog can take action before things are logged to console.
*/
let route = function(statusArg: boolean) {
if (statusArg === true) {
console.log = beautyConsole.log;
console.error = beautyConsole.error;
} else {
console.log = nativeLog;
}
};
export let beautyConsole = {
log: function(logArg: any) {
if (oraActive) {
activeOra.pause();
nativeLog.apply(nativeLog, arguments);
activeOra.start();
} else {
nativeLog.apply(nativeLog, arguments);
}
},
error: function() {
if (oraActive) {
activeOra.pause();
nativeLog.apply(nativeError, arguments);
activeOra.start();
} else {
nativeLog.apply(nativeError, arguments);
}
}
};
route(true);