Skip to content

Commit

Permalink
Make internal-specific icon and level, as per PR comment:
Browse files Browse the repository at this point in the history
#948 (comment)

Co-authored-by: BryceStevenWilley <[email protected]>
  • Loading branch information
plocket and BryceStevenWilley committed Oct 30, 2024
1 parent f981e6a commit 2123101
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
28 changes: 14 additions & 14 deletions lib/utils/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class Log {
console.error( `${before}${metadata_str}:`, ...logs );
} catch ( pre_throw_error ) {
this.debug({
code: `ALK0215`, level: `warn`, context: `internal log`,
icon: `🖊️`, code: `ALK0215`, context: `internal log`, level: `note`,
}, `Skipped logging metadata before throwing the error`, pre_throw_error );
}

Expand All @@ -256,7 +256,7 @@ class Log {
} catch ( console_log_error ) {
// Fail silently
this.debug({
level: `warn`, code: `ALK0211`, context: `internal log`,
icon: `🖊️`, code: `ALK0211`, context: `internal log`, level: `note`,
}, `Skipped saving a ${ level } message to the debug log`, console_log_error );
} finally {
return formatted;
Expand Down Expand Up @@ -320,16 +320,16 @@ class Log {
// Answer: `._console` doesn't use `formatted`, just returns it.
formatted = `${ before }${ metadata_str }: ${ stringified }`;
} catch ( formatted_log_error ) {
formatted = `🐛 ALK0212 internal debug WARNING [${ Date.now() }]: Skipped formatting debug logs.`;
formatted = `🖊️ ALK0212 internal debug NOTE [${ Date.now() }]: Skipped formatting debug logs.`;
this._save_to_debug_safely({ unexpected: true, text: formatted });
this._save_to_debug_safely({ unexpected: true, text: formatted_log_error.stack });
}

let unexpected = `warn error`.includes( level );
let unexpected = `warn error note`.includes( level );
this._save_to_debug_safely({ unexpected, text: formatted });

} catch ( debug_error ) {
formatted = `🐛 ALK0217 internal debug WARNING [${ Date.now() }]: Skipped log.debug()\n${ debug_error.stack }`;
formatted = `🖊️ ALK0217 internal debug NOTE [${ Date.now() }]: Skipped log.debug()\n${ debug_error.stack }`;
this._save_to_debug_safely({ unexpected: true, text: formatted });
this._save_to_debug_safely({ unexpected: true, text: debug_error.stack });
}
Expand Down Expand Up @@ -387,7 +387,7 @@ class Log {
metadata_str = metadata_list.join(` `);

} catch ( metadata_error ) {
this._save_to_debug_safely({ unexpected: true, text: `🐛 ALK0219 internal log metadata WARNING [${ Date.now() }]: Skipped creating metadata.` });
this._save_to_debug_safely({ unexpected: true, text: `🖊️ ALK0219 internal log metadata NOTE [${ Date.now() }]: Skipped creating metadata.` });
this._save_to_debug_safely({ unexpected: true, text: metadata_error.stack });
}
return metadata_str;
Expand Down Expand Up @@ -546,10 +546,10 @@ class Log {

// Otherwise error should be `undefined`. If not, we get a warning.
} else if ( maybe_error !== undefined ) {
this._save_to_debug_safely({ unexpected: true, text: `🐛 ALK0223 internal debug WARNING [${ Date.now() }]: Only logs that throw should give a value to \`error\`. Skipping the value.` });
this._save_to_debug_safely({ unexpected: true, text: `🖊️ ALK0223 internal debug NOTE [${ Date.now() }]: Only logs that throw should give a value to \`error\`. Skipping the value.` });
}
} catch ( combining_error_error ) {
this._save_to_debug_safely({ unexpected: true, text: `🐛 ALK0226 internal debug WARNING [${ Date.now() }]: Skipped combining the logs.` });
this._save_to_debug_safely({ unexpected: true, text: `🖊️ ALK0226 internal debug NOTE [${ Date.now() }]: Skipped combining the logs.` });
this._save_to_debug_safely({ unexpected: true, text: combining_error_error.stack });
}

Expand Down Expand Up @@ -578,7 +578,7 @@ class Log {
return false; // Did not trigger an error

} catch ( maybe_error_stringify_error ) {
this._save_to_debug_safely({ unexpected: true, text: `🐛 ALK0224 internal log WARNING [${ Date.now() }]: Skipped JSON.stringify().` });
this._save_to_debug_safely({ unexpected: true, text: `🖊️ ALK0224 internal log NOTE [${ Date.now() }]: Skipped JSON.stringify().` });
this._save_to_debug_safely({ unexpected: true, text: maybe_error_stringify_error.stack });
return true; // Triggered an error
}
Expand All @@ -594,7 +594,7 @@ class Log {
safe_val = inspected;

} catch ( risky_val_inspect_error ) {
this._save_to_debug_safely({ unexpected: true, text: `🐛 ALK0222 internal log WARNING [${ Date.now() }]: Skipped inspecting risky value.` });
this._save_to_debug_safely({ unexpected: true, text: `🖊️ ALK0222 internal log NOTE [${ Date.now() }]: Skipped inspecting risky value.` });
this._save_to_debug_safely({ unexpected: true, text: risky_val_inspect_error.stack });
// If even that failed, we can only return a vague message
safe_val = `ALKiln was unable to parse the value of \`error\`. Skipped parsing it.`;
Expand All @@ -608,7 +608,7 @@ class Log {
try {
return util.inspect( value, { depth: 8, maxArrayLength: null, maxStringLength: null, });
} catch ( direct_inspect_err ) {
return `🐛 ALK0228 inspect log WARNING [${ Date.now() }]: Skipped util.inspect. ${ direct_inspect_err.stack }`;
return `🖊️ ALK0228 inspect log NOTE [${ Date.now() }]: Skipped util.inspect. ${ direct_inspect_err.stack }`;
}
}

Expand Down Expand Up @@ -798,7 +798,7 @@ class Log {
// If this is our first time failing to write to the debug log, console
// warn about it.
this.fs_append_to_debug_file_failed = true;
console.warn(`🐛 ALK0213 internal debug WARNING [${ Date.now() }]: Skipped appending to debug file.`);
console.warn(`🖊️ ALK0213 internal debug NOTE [${ Date.now() }]: Skipped appending to debug file.`);
console.warn( fs_append_error );
}

Expand All @@ -821,7 +821,7 @@ class Log {
* */
try {
console.warn(
`🐛 ALK0229 internal debug WARNING [${ Date.now() }]:`,
`🖊️ ALK0229 internal debug NOTE [${ Date.now() }]:`,
`Skipped logging data to console.`,
final_error
);
Expand Down Expand Up @@ -884,7 +884,7 @@ class Log {
// Write to the debug and report files
this._record_stdout( whole_log );
} catch ( stdout_error ) {
this._save_to_debug_safely({ unexpected: true, text: `🐛 ALK0227 internal stdout WARNING [${ Date.now() }]: Skipped stdout.`});
this._save_to_debug_safely({ unexpected: true, text: `🖊️ ALK0227 internal stdout NOTE [${ Date.now() }]: Skipped stdout.`});
this._save_to_debug_safely({ unexpected: true, text: stdout_error.stack });
};

Expand Down
24 changes: 16 additions & 8 deletions tests/unit_tests/log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const temp_log_path = `_alkiln-log_test_path`;
* let old_stderr;
* */

// TODO: break out each `expect`
// TODO: break out each `expect`?

/** Discuss: Save a log folder for each of the tests? I'm not sure it would be
practical to look through.*/
Expand Down Expand Up @@ -109,7 +109,17 @@ describe(`An instance of log`, function () {
});
})

// TODO: Given a log that's empty strings, returns and saves the right values - spaces
describe(`given logs with multiple empty strings`, function () {
it(`.debug returns multiple spaces`, async function() {
let returned = log.debug( {}, ``, ``, ``, `` );
expect( returned ).to.include(` `);
expect( returned ).to.not.include(`Skip`);
});
it(`.debug stores the right text in the debug file`, async function() {
expect_debug_file_to_include(` `);
expect_debug_file_to_not_include(`Skip`);
});
})

describe(`with an empty ._console`, function () {
it(`returns the right values`, async function() {
Expand Down Expand Up @@ -146,9 +156,6 @@ describe(`An instance of log`, function () {
});
})

// TODO: test that passing an Error with `.error` prop to `._console()`
// doesn't save to the unexpected results file.

describe(`with an empty log.success`, function () {
it(`returns the right values`, async function() {
let returned = log.success();
Expand Down Expand Up @@ -331,11 +338,11 @@ describe(`An instance of log`, function () {
})

describe(`.throw() with an actual error`, function () {
it(`doesn't include .Log in its stack`, async function() {
it(`doesn't include ".Log" in its stack`, async function() {
let error_to_test;
try {
let options = {
error: new Error(`No .Log should be in this stack`),
error: new Error(`No ".Log" should be in this stack`),
do_throw: true, // Not really needed
};
log.throw( options, `custom_THROW_log` );
Expand All @@ -345,7 +352,6 @@ describe(`An instance of log`, function () {
expect( error_to_test.stack ).to.not.include(`at Log.throw`);
expect( error_to_test.stack ).to.not.include(`Skip`);
});
/** TODO: Add debug/unexpected output file tests? */
})

describe(`when given 1 option and no logs, ._console()`, function () {
Expand Down Expand Up @@ -418,11 +424,13 @@ describe(`An instance of log`, function () {
expect_debug_file_to_include(`throw circular reference error`);
expect_debug_file_to_include(`circular error`);
expect_debug_file_to_include(`[Circular *1], [Circular *1]`);
expect_debug_file_to_include(`ALK0224`);
});
it(`stores the right value in the unexpected file`, async function() {
expect_unexpected_output_file_to_include(`throw circular reference error`);
expect_unexpected_output_file_to_include(`circular error`);
expect_unexpected_output_file_to_include(`[Circular *1], [Circular *1]`);
expect_unexpected_output_file_to_include(`ALK0224`);
});
})

Expand Down

0 comments on commit 2123101

Please sign in to comment.