Skip to content

Commit

Permalink
Fix security issue and added categories to the log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
galvesribeiro committed Jul 24, 2019
1 parent 96a19d8 commit d8221f4
Show file tree
Hide file tree
Showing 10 changed files with 556 additions and 546 deletions.
55 changes: 16 additions & 39 deletions src/Blazor.Extensions.Logging.JS/package-lock.json

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

4 changes: 2 additions & 2 deletions src/Blazor.Extensions.Logging.JS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"lodash": ">=4.17.11"
"lodash": ">=4.17.13"
},
"devDependencies": {
"@types/emscripten": "0.0.31",
"ts-loader": "^4.4.2",
"typescript": "^2.9.2",
"typescript": "^3.5.2",
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0"
}
Expand Down
81 changes: 42 additions & 39 deletions src/Blazor.Extensions.Logging.JS/src/BrowserConsoleLogger.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import { LogObject, LogObjectType, LogLevel } from './LogObject';

interface IBrowserConsoleLogger {
Log(logObjectValue: string): void;
}

export class BrowserConsoleLogger implements IBrowserConsoleLogger {
Log(logObjectValue: string): void {
const logObject: LogObject = JSON.parse(logObjectValue);
let logMethod: Function = console.log;

// if we've a table, we'll print it as a table anyway, it is unlikely that the developer want to log errornous data as a table.
if (logObject.type === LogObjectType.Table) {
logMethod = console.table;
} else {
switch (logObject.logLevel) {
case LogLevel.Trace:
logMethod = console.trace;
break;
case LogLevel.Debug:
logMethod = console.debug;
break;
case LogLevel.Warning:
logMethod = console.warn;
break;
case LogLevel.Error:
case LogLevel.Critical:
logMethod = console.error;
break;
}
}

logMethod(logObject.payload);

if (logObject.exception) {
logMethod("Exception: ", logObject.exception);
}
}
}
import { LogObject, LogObjectType, LogLevel } from './LogObject';

interface IBrowserConsoleLogger {
Log(logObjectValue: string): void;
}

export class BrowserConsoleLogger implements IBrowserConsoleLogger {
Log(logObjectValue: string): void {
const logObject: LogObject = JSON.parse(logObjectValue);
let logMethod: Function = console.log;

// if we've a table, we'll print it as a table anyway, it is unlikely that the developer want to log errornous data as a table.
if (logObject.Type === LogObjectType.Table) {
logMethod = console.table;
} else {
switch (logObject.LogLevel) {
case LogLevel.Trace:
logMethod = console.trace;
break;
case LogLevel.Debug:
logMethod = console.debug;
break;
case LogLevel.Warning:
logMethod = console.warn;
break;
case LogLevel.Error:
case LogLevel.Critical:
logMethod = console.error;
break;
}
}
if (logObject.Type == LogObjectType.Table) {
logMethod(logObject.Payload);
} else {
logMethod(`[${logObject.Category}]`, logObject.Payload);
}

if (logObject.Exception) {
logMethod(`[${logObject.Category}] Exception: `, logObject.Exception);
}
}
}
47 changes: 24 additions & 23 deletions src/Blazor.Extensions.Logging.JS/src/LogObject.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
export type LogObject = {
logLevel: LogLevel;
type: LogObjectType;
payload: any;
exception: string;
}

// enum coming from Microsoft.Extensions.Logging
export enum LogLevel {
Trace = 0,
Debug = 1,
Information = 2,
Warning = 3,
Error = 4,
Critical = 5,
None = 6
}

export enum LogObjectType {
String = 0,
Object = 1,
Table = 2
}
export type LogObject = {
Category: string;
LogLevel: LogLevel;
Type: LogObjectType;
Payload: any;
Exception: string;
}

// enum coming from Microsoft.Extensions.Logging
export enum LogLevel {
Trace = 0,
Debug = 1,
Information = 2,
Warning = 3,
Error = 4,
Critical = 5,
None = 6
}

export enum LogObjectType {
String = 0,
Object = 1,
Table = 2
}
Loading

0 comments on commit d8221f4

Please sign in to comment.