Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
improved logging and output
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Feb 8, 2018
1 parent d17ca0a commit b6c34a6
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Share via Facebook](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Facebook.png)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded) [![Share via Twitter](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Twitter.png)](https://twitter.com/intent/tweet?source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&text=vscode-deploy-reloaded:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&via=mjkloubert) [![Share via Google+](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Google+.png)](https://plus.google.com/share?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Pinterest](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Pinterest.png)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&media=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif&description=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.) [![Share via Reddit](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Reddit.png)](https://www.reddit.com/submit?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded) [![Share via LinkedIn](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/LinkedIn.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded&summary=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Wordpress](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Wordpress.png)](https://wordpress.com/press-this.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded&s=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&i=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif) [![Share via Email](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Email.png)](mailto:?subject=vscode-deploy-reloaded&body=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20'vs-deploy'%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded)


## 0.37.0 (February 8th, 2018; log files)
## 0.38.0 (February 8th, 2018; log files)

* logs will be written to `.vscode-deploy-reloaded/.logs` sub folder of the user's home directory now ... files, which are older than 31 days, will be deleted automatically

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-deploy-reloaded",
"displayName": "Deploy (Reloaded)",
"description": "Deploys files of a workspace to a destination.",
"version": "0.37.0",
"version": "0.38.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.19.0"
Expand Down
3 changes: 1 addition & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,7 @@ export function isBinaryContent(data: Buffer): Promise<boolean> {
* @return {boolean} Is boolean or not.
*/
export function isBool(val: any): val is boolean {
return !isNullOrUndefined(val) &&
'boolean' === typeof val;
return _.isBoolean(val);
}

/**
Expand Down
25 changes: 18 additions & 7 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,10 @@ NEW_CONSOLE_LOGGER.addAction((ctx) => {
}
time = deploy_helpers.asUTC(time);

if (ctx.type > LogType.Info) {
return;
if (LogType.Trace !== ctx.type) {
if (ctx.type > LogType.Info) {
return;
}
}

let msg = `${LogType[logType].toUpperCase().trim()}`;
Expand All @@ -464,12 +466,21 @@ NEW_CONSOLE_LOGGER.addAction((ctx) => {
msg += ' ' + TAG;
}

let logMsg = deploy_helpers.toStringSafe(ctx.message);
if (LogType.Trace === ctx.type) {
const STACK = deploy_helpers.toStringSafe(
(new Error()).stack
).split("\n").filter(l => {
return l.toLowerCase()
.trim()
.startsWith('at ');
}).join("\n");

logMsg += `\n\nStack:\n${STACK}`;
}

msg += ` - [${time.format('DD/MMM/YYYY:HH:mm:ss')} +0000] "${
_.replace(
deploy_helpers.toStringSafe(ctx.message),
/"/ig,
'\\"'
)
_.replace(logMsg, /"/ig, '\\"')
}"${OS.EOL}`;

const LOG_FILE = Path.resolve(
Expand Down
164 changes: 164 additions & 0 deletions src/output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/**
* This file is part of the vscode-deploy-reloaded distribution.
* Copyright (c) Marcel Joachim Kloubert.
*
* vscode-deploy-reloaded is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 3.
*
* vscode-deploy-reloaded is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import * as deploy_helpers from './helpers';
import * as deploy_log from './log';
import * as deploy_objects from './objects';
import * as vscode from 'vscode';


/**
* A channel writer.
*
* @param {string} text The text to write.
* @param {boolean} addNewLine Add new line or not.
*/
export type ChannelWriter = (context: ChannelWriterContext) => void;

/**
* A context for a channel writer.
*/
export interface ChannelWriterContext {
/**
* Add new line or not.
*/
readonly addNewLine: boolean;
/**
* The base channel.
*/
readonly baseChannel: vscode.OutputChannel;
/**
* The text to write.
*/
readonly text: string;
}


/**
* A wrapper for an output channel.
*/
export class OutputChannelWrapper extends deploy_objects.DisposableBase implements vscode.OutputChannel {
private readonly _OWNS_CHANNEL: boolean;
private readonly _WRITERS: ChannelWriter[] = [];

/**
* Initializes a new instance of that class.
*
* @param {vscode.OutputChannel} baseChannel The base channel.
* @param {boolean} [ownsChannel] Also dispose base channel or not.
*/
public constructor(public readonly baseChannel: vscode.OutputChannel, ownsChannel?: boolean) {
super();

this._OWNS_CHANNEL = deploy_helpers.toBooleanSafe(ownsChannel);
}

/**
* Adds a writer.
*
* @param {ChannelWriter} writer The writer to add.
*
* @chainable
*/
public addWriter(writer: ChannelWriter): this {
if (writer) {
this._WRITERS.push(writer);
}

return this;
}

/** @inheritdoc */
public append(value: any) {
value = deploy_helpers.toStringSafe(value);

this.invokeForBaseChannel(this.baseChannel.append,
[ value ]);

this.sendToWriters(value, false);
}

/** @inheritdoc */
public appendLine(value: any) {
value = deploy_helpers.toStringSafe(value);

this.invokeForBaseChannel(this.baseChannel.appendLine,
[ value ]);

this.sendToWriters(value, true);
}

/** @inheritdoc */
public clear() {
this.invokeForBaseChannel(this.baseChannel.clear, arguments);
}

/** @inheritdoc */
public hide() {
this.invokeForBaseChannel(this.baseChannel.hide, arguments);
}

private invokeForBaseChannel<TResult = any>(method: (...args: any[]) => TResult, args?: IArguments | any[]): TResult {
if (method) {
return method.apply(
this.baseChannel,
args || []
);
}
}

/** @inheritdoc */
public get name() {
return this.baseChannel.name;
}

/** @inheritdoc */
protected onDispose() {
while (this._WRITERS.length > 0) {
this._WRITERS.pop();
}

if (this._OWNS_CHANNEL) {
this.invokeForBaseChannel(this.baseChannel.dispose, []);
}
}

private sendToWriters(text: string, addNewLine: boolean) {
if ('' === text) {
return;
}

for (const WRITER of this._WRITERS) {
try {
WRITER({
addNewLine: addNewLine,
baseChannel: this.baseChannel,
text: text,
});
}
catch (e) {
deploy_log.CONSOLE
.trace(e, 'output.OutputChannelWrapper.sendToWriters(1)');
}
}
}

/** @inheritdoc */
public show() {
this.invokeForBaseChannel(this.baseChannel.show, arguments);
}
}
21 changes: 18 additions & 3 deletions src/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import * as deploy_list from './list';
import * as deploy_log from './log';
import * as deploy_mappings from './mappings';
import * as deploy_objects from './objects';
import * as deploy_output from './output';
import * as deploy_packages from './packages';
import * as deploy_plugins from './plugins';
import * as deploy_pull from './pull';
Expand Down Expand Up @@ -282,8 +283,9 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
*/
protected _lastConfigUpdate: Moment.Moment;
private readonly _LOGGER = new deploy_log.ActionLogger();
private _OLD_ENV_VARS: deploy_contracts.KeyValuePairs = {};
private _PACKAGE_BUTTONS: PackageWithButton[] = [];
private readonly _OLD_ENV_VARS: deploy_contracts.KeyValuePairs = {};
private readonly _OUTPUT_CHANNEL: deploy_output.OutputChannelWrapper;
private readonly _PACKAGE_BUTTONS: PackageWithButton[] = [];
private _packages: deploy_packages.Package[];
private _rootPath: string | false;
private _selectedSwitches: deploy_contracts.KeyValuePairs;
Expand Down Expand Up @@ -311,6 +313,9 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
public readonly context: WorkspaceContext) {
super();

this._OUTPUT_CHANNEL = new deploy_output.OutputChannelWrapper(
context.outputChannel
);
this.state = new WorkspaceMemento(this,
context.extension.workspaceState);
}
Expand Down Expand Up @@ -1859,6 +1864,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
}

ME.setupLogger();
ME.setupOutputChannel();

ME._rootPath = false;

Expand Down Expand Up @@ -2497,6 +2503,9 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c

/** @inheritdoc */
protected onDispose() {
// dispose output channel
this._OUTPUT_CHANNEL.dispose();

// and last but not least:
// dispose logger
try {
Expand All @@ -2519,7 +2528,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
* Gets the output channel of that workspace.
*/
public get output(): vscode.OutputChannel {
return this.context.outputChannel;
return this._OUTPUT_CHANNEL;
}

/**
Expand Down Expand Up @@ -3445,6 +3454,12 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
deploy_log.CONSOLE
.log(ctx.type, ctx.message, ctx.tag);
});

//TODO: add actions from config
}

private setupOutputChannel() {
//TODO: add writers from config
}

/**
Expand Down

0 comments on commit b6c34a6

Please sign in to comment.