-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2039 from filrak/vs-modules
Remove stacktrace.js, refactored logger API
- Loading branch information
Showing
19 changed files
with
68 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,41 @@ | ||
import StackTrace from 'stacktrace-js' | ||
|
||
const bgColorStyle = (color) => `color: white; background: ${color}; padding: 4px; font-weight: bold; font-size: 0.8em'` | ||
|
||
class VueStorefrontLogger { | ||
private mode: string; | ||
constructor () { | ||
this.mode = process.env.NODE_ENV | ||
} | ||
/** | ||
* Inform about something that happened in the app (for example client/server/cache itneractions). | ||
* Provide meaningful data into `context` for easier debugging | ||
*/ | ||
public info (message: string, properties?: { | ||
tag?: string | ||
context?: { label: string, value: any } | ||
}) : void { | ||
if (this.mode !== 'production' && typeof window !== 'undefined') { | ||
StackTrace.get().then(trace => { | ||
trace.shift() // remove unnecessary stack frame to logger | ||
if (properties && properties.tag) { | ||
console.groupCollapsed('%cVSF%c %c' + properties.tag +'%c ' + message, | ||
bgColorStyle('green'), 'color: inherit', bgColorStyle('gray'), 'color: inherit') | ||
} else { | ||
console.groupCollapsed('%cVSF%c ' + message, | ||
bgColorStyle('green'), 'color: inherit') | ||
} | ||
if (trace.length > 1) { | ||
console.log('%cSource:%c ' + 'webpack:///.'+trace[0].fileName.substring(10) + ':' + trace[0].lineNumber, 'font-weight: bold', 'font-weight: normal') | ||
console.log('%cStack trace:', 'font-weight: bold', trace) | ||
} | ||
if (properties && properties.context) { | ||
console.log('%c' + properties.context.label + ' ', 'font-weight: bold', properties.context.value) | ||
} | ||
console.groupEnd() | ||
}) | ||
const Logger = { | ||
info : function (message, tag = null, context = null) { | ||
if (typeof window !== 'undefined') { | ||
if (tag) { | ||
let msg ='%cVSF%c %c' + tag +'%c ' + message | ||
return console.log.bind(window.console, '%cVSF%c %c' + tag +'%c ' + message, bgColorStyle('green'), 'color: inherit', bgColorStyle('gray'), 'font-weight: bold', { context }); | ||
} else { | ||
return console.log.bind(window.console, '%cVSF%c ' + message, bgColorStyle('green'), 'font-weight: bold', { context }); | ||
} | ||
} else { | ||
return function (a, b) {} | ||
} | ||
} | ||
|
||
/** | ||
* Warn develoeprs about things that may cause some problems | ||
* Provide meaningful data into `context` for easier debugging | ||
* */ | ||
public warn (message: string, properties?: { | ||
tag?: string | ||
context?: { label: string, value: any } | ||
}) : void { | ||
if (this.mode !== 'production' && typeof window !== 'undefined') { | ||
StackTrace.get().then(trace => { | ||
trace.shift() // remove unnecessary stack frame to logger | ||
if (properties && properties.tag) { | ||
console.groupCollapsed('%cVSF%c %c' + properties.tag +'%c ' + message, | ||
bgColorStyle('#ff6600'), 'color: inherit', bgColorStyle('gray'), 'color: #ff6600') | ||
} else { | ||
console.groupCollapsed('%cVSF%c ' + message, | ||
bgColorStyle('#ff6600'), 'color: inherit') | ||
} | ||
if (trace.length > 1) { | ||
console.log('%cSource:%c ' + 'webpack:///.'+trace[0].fileName.substring(10) + ':' + trace[0].lineNumber, 'font-weight: bold', 'font-weight: normal') | ||
console.log('%cStack trace:', 'font-weight: bold', trace) | ||
} | ||
if (properties && properties.context) { | ||
console.log('%c' + properties.context.label + ' ', 'font-weight: bold', properties.context.value) | ||
} | ||
console.groupEnd() | ||
}) | ||
}, | ||
warn: function (message, tag = null, context = null) { | ||
if (typeof window !== 'undefined') { | ||
if (tag) { | ||
return console.warn.bind(window.console, '%cVSF%c %c' + tag +'%c ' + message, bgColorStyle('orange'), 'color: inherit', bgColorStyle('gray'), 'font-weight: bold', { context }); | ||
} else { | ||
return console.warn.bind(window.console, '%cVSF%c ' + message, bgColorStyle('orange'), 'font-weight: bold', { context }); | ||
} | ||
} else { | ||
return function (a, b) {} | ||
} | ||
} | ||
public error (message: string, properties?: { | ||
tag?: string | ||
context?: { label: string, value: any } | ||
}) : void { | ||
if (this.mode !== 'production' && typeof window !== 'undefined') { | ||
StackTrace.get().then(trace => { | ||
trace.shift() // remove unnecessary stack frame to logger | ||
if (properties && properties.tag) { | ||
console.groupCollapsed('%cVSF%c %c' + properties.tag +'%c ' + message, | ||
bgColorStyle('red'), 'color: inherit', bgColorStyle('gray'), 'color: red') | ||
} else { | ||
console.groupCollapsed('%cVSF%c ' + message, | ||
bgColorStyle('red'), 'color: inherit') | ||
} | ||
if (trace.length > 1) { | ||
console.log('%cSource:%c ' + 'webpack:///.'+trace[0].fileName.substring(10) + ':' + trace[0].lineNumber, 'font-weight: bold', 'font-weight: normal') | ||
console.log('%cStack trace:', 'font-weight: bold', trace) | ||
} | ||
if (properties && properties.context) { | ||
console.log('%c' + properties.context.label + ' ', 'font-weight: bold', properties.context.value) | ||
} | ||
console.groupEnd() | ||
}) | ||
}, | ||
error: function (message, tag = null, context = null) { | ||
if (typeof window !== 'undefined') { | ||
if (tag) { | ||
return console.error.bind(window.console, '%cVSF%c %c' + tag +'%c ' + message, bgColorStyle('red'), 'color: inherit', bgColorStyle('gray'), 'font-weight: bold', { context }); | ||
} else { | ||
return console.error.bind(window.console, '%cVSF%c ' + message, bgColorStyle('red'), 'font-weight: bold', { context }); | ||
} | ||
} else { | ||
return function (a, b) {} | ||
} | ||
} | ||
} | ||
|
||
export const Logger = new VueStorefrontLogger() | ||
const bgColorStyle = (color) => `color: white; background: ${color}; padding: 4px; font-weight: bold; font-size: 0.8em'` | ||
|
||
export { Logger } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.