-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(DownloadLogs): Implemented Download Logs Feature
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* | ||
* @param error | ||
*/ | ||
export function formatError(error: any) { | ||
if (!error) { | ||
return ''; | ||
} | ||
|
||
if (error.stack) { | ||
return `fileName: '${error.fileName}', name: '${error.name}' lineNumber:${error.lineNumber} columnNumber:${error.columnNumber} message:'${error.message}'.`; | ||
} | ||
|
||
if (error.message) { | ||
return error.message; | ||
} | ||
return JSON.stringify(error); | ||
} | ||
|
||
/** | ||
* | ||
* @param text | ||
* @param leadingCharactersToKeep | ||
*/ | ||
export function concise(text = '', leadingCharactersToKeep = 32) { | ||
if (text.length > leadingCharactersToKeep) { | ||
return `${text.substring(0, leadingCharactersToKeep - 1)}...`; | ||
} | ||
return text; | ||
// return text ? (text.length > leadingCharactersToKeep ? text.substring(0, leadingCharactersToKeep - 1) + '...' : text) : ''; | ||
} | ||
|
||
export function downloadLogs() { | ||
let content = localStorage.getItem("log"); | ||
if (!content) { | ||
content = ""; | ||
} | ||
const a = document.createElement("a"); | ||
a.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(content)); | ||
a.setAttribute("download", "msteams-integration.log"); | ||
a.style.display = "none"; | ||
document.body.appendChild(a); | ||
a.click(); | ||
document.body.removeChild(a); | ||
} | ||
|
||
export class Logger { | ||
static maxLogSizeInBytes: 500000; | ||
static log(level: string, msg: string) { | ||
const logMsg: string[] = []; | ||
logMsg.push(new Date().toISOString()," ", "[", level, "]", " ", msg, "\n"); | ||
if (level == "error") { | ||
//console.log(getErrorObject()); | ||
} | ||
if (level !== "debug") { | ||
let log = localStorage.getItem("log"); | ||
if (!log) { | ||
log = ""; | ||
} | ||
if (log.length > Logger.maxLogSizeInBytes) { | ||
localStorage.removeItem("log"); | ||
log = ""; | ||
} | ||
localStorage.setItem("log", log + logMsg.join("")); | ||
} | ||
// console.log(`${new Date().toISOString()} [${level}] ${msg}\n`, 'test' ); | ||
} | ||
|
||
static debug(msg: string) { | ||
Logger.log('debug', msg); | ||
} | ||
|
||
static info(msg: string) { | ||
Logger.log('info', msg); | ||
} | ||
|
||
static error(msg: string) { | ||
Logger.log('error', msg); | ||
} | ||
} | ||
|
||
export enum LOGGER { | ||
ERROR = "error", | ||
WARN = "warn", | ||
INFO = "info", | ||
LOG = "log", | ||
TRACE = "trace" | ||
} |
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