mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import chalk from "chalk";
|
|
import * as ip from "ip"
|
|
|
|
const divider = chalk.gray('-----------------------------------');
|
|
|
|
export const logger = {
|
|
// Called when express.js app starts on given port w/o errors
|
|
appStarted: (port: string | number, title = 'Server started ') => {
|
|
console.log(chalk.underline.bold(title) + ` ${chalk.green('✓')}`);
|
|
console.log(`
|
|
${chalk.bold('Access URLs:')}
|
|
${divider}
|
|
Localhost: ${chalk.magenta(`http://localhost:${port}`)}
|
|
LAN: ${chalk.magenta(`http://${ip.address()}:${port}`)}
|
|
${divider}
|
|
`);
|
|
},
|
|
|
|
error(message: string, error: any) {
|
|
let errString = ""
|
|
try {
|
|
errString = JSON.stringify(error, null, 2);
|
|
} catch (e) {
|
|
errString = String(error);
|
|
}
|
|
console.error(chalk.bold.red(`[ERROR] -> ${message}`), errString);
|
|
}
|
|
};
|
|
|
|
export function sanitizeHeaders(headers: { [name: string]: string }) {
|
|
if (headers.Authorization) {
|
|
const [authType, authToken] = headers.Authorization.split(" ");
|
|
headers.Authorization = `${authType} *****`
|
|
}
|
|
return headers;
|
|
}
|