Skip to content

Commit

Permalink
style: improved console marker styles
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Oct 18, 2024
1 parent 1424bad commit ab9fa19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
22 changes: 15 additions & 7 deletions core/components/Logger/FXServerLogger/ConsoleTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ type StyleChannelConfig = {
line?: ChalkInstance;
}


//Precalculating some styles
const chalkToStr = (color: ChalkInstance) => color('\x00').split('\x00')[0];
const precalcMarkerAdminCmd = chalkToStr(chalk.bgHex('#e6b863').black);
const precalcMarkerSystemCmd = chalkToStr(chalk.bgHex('#36383D').hex('#CCCCCC'));
const precalcMarkerInfo = chalkToStr(chalk.bgBlueBright.black);
const ANSI_RESET = '\x1B[0m';
const ANSI_ERASE_LINE = '\x1b[K';

const STYLES = {
[ConsoleLineType.StdOut]: null, //fully shortcircuited
[ConsoleLineType.StdErr]: {
Expand All @@ -36,23 +45,22 @@ const STYLES = {
},
[ConsoleLineType.MarkerAdminCmd]: {
web: {
prefix: chalk.bgYellowBright.bold.black,
line: chalk.bold.yellowBright,
prefix: chalk.bold,
line: x => `${precalcMarkerAdminCmd}${x}${ANSI_ERASE_LINE}${ANSI_RESET}`,
},
stdout: false,
},
[ConsoleLineType.MarkerSystemCmd]: {
//chalk.bgHex('#36383D').bold.hex('#CCCCCC')
web: {
prefix: chalk.bgWhiteBright.bold.black,
line: chalk.bold.blackBright,
prefix: chalk.bold,
line: x => `${precalcMarkerSystemCmd}${x}${ANSI_ERASE_LINE}${ANSI_RESET}`,
},
stdout: false,
},
[ConsoleLineType.MarkerInfo]: {
web: {
prefix: chalk.bgBlueBright.bold.black,
line: chalk.bgBlueBright.bold.black,
prefix: chalk.bold,
line: x => `${precalcMarkerInfo}${x}${ANSI_ERASE_LINE}${ANSI_RESET}`,
},
stdout: {
prefix: chalk.bgBlueBright.bold.black,
Expand Down
23 changes: 11 additions & 12 deletions core/components/Logger/FXServerLogger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ export default class FXServerLogger extends LoggerBase {
* lrStream, websocket, and process stdout.
*/
private ingest(type: ConsoleLineType, data: string, context?: string) {
//force line skip to create separation
if (type === ConsoleLineType.MarkerInfo) {
const lineBreak = this.transformer.lastEol ? '\n' : '\n\n';
this.fileBuffer += lineBreak;
if (this.recentBuffer.length) {
this.txAdmin.webServer.webSocket.buffer('liveconsole', lineBreak);
this.appendRecent(lineBreak);
}
}

//Process the data
const { webBuffer, stdoutBuffer, fileBuffer } = this.transformer.process(type, data, context);

Expand Down Expand Up @@ -130,8 +120,17 @@ export default class FXServerLogger extends LoggerBase {
* Writes to the log that the server is booting
*/
public logFxserverBoot(pid: string) {
const msg = getLogDivider(`[${pid}] FXServer Starting`);
this.ingest(ConsoleLineType.MarkerInfo, msg);
//force line skip to create separation
if(this.recentBuffer.length){
const lineBreak = this.transformer.lastEol ? '\n' : '\n\n';
this.ingest(ConsoleLineType.MarkerInfo, lineBreak);
}
//need to break line
const multiline = getLogDivider(`[${pid}] FXServer Starting`);
for (const line of multiline.split('\n')) {
if (!line.length) break;
this.ingest(ConsoleLineType.MarkerInfo, `${line} \n`);
}
}


Expand Down

0 comments on commit ab9fa19

Please sign in to comment.