-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
teacher tool: initial theming from target (#9830)
* initial theming from target * temp file rename * readme update * moar readme update * add reducer case * improved error logging
- Loading branch information
1 parent
8bea667
commit 27109ad
Showing
11 changed files
with
212 additions
and
113 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,45 @@ | ||
const formatMessageForConsole = (message: string) => { | ||
const timestamp = () => { | ||
const time = new Date(); | ||
return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}] ${message}`; | ||
} | ||
return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}]`; | ||
}; | ||
|
||
const formatName = (name: string) => { | ||
return name.toLowerCase().replace(/ /g, "_"); | ||
} | ||
}; | ||
|
||
export const logError = (name: string, details: string) => { | ||
pxt.tickEvent("teachertool.error", { name: formatName(name), message: details }); | ||
console.error(formatMessageForConsole(`${name}: ${details}`)); | ||
} | ||
export const logError = ( | ||
errorCode: string, | ||
message?: any, | ||
data: pxt.Map<string | number> = {} | ||
) => { | ||
errorCode = formatName(errorCode); | ||
let dataObj = { ...data }; | ||
if (message) { | ||
if (typeof message === "object") { | ||
dataObj = { ...dataObj, ...message }; | ||
// Look for non-enumerable properties found on Error objects | ||
["message", "stack", "name"].forEach(key => { | ||
if (message[key]) { | ||
dataObj[key] = message[key]; | ||
} | ||
}); | ||
} else { | ||
dataObj.message = message; | ||
} | ||
} | ||
pxt.tickEvent("teachertool.error", { | ||
...dataObj, | ||
errorCode, | ||
}); | ||
console.error(timestamp(), errorCode, dataObj); | ||
}; | ||
|
||
export const logInfo = (name: string, message: string) => { | ||
pxt.tickEvent(`teachertool.${formatName(name)}`, { message: message }); | ||
console.log(formatMessageForConsole(message)); | ||
} | ||
export const logInfo = (message: any) => { | ||
console.log(timestamp(), message); | ||
}; | ||
|
||
export const logDebug = (message: string) => { | ||
export const logDebug = (message: any) => { | ||
if (pxt.BrowserUtils.isLocalHost() || pxt.options.debug) { | ||
console.log(formatMessageForConsole(message)); | ||
console.log(timestamp(), message); | ||
} | ||
} | ||
}; |
Oops, something went wrong.