FEATURE: add shouldShowTime

Relates to [this forum request](https://forums.meteor.com/t/suggestions-for-logging-in-galaxy/63119/6?u=grubba).

Those that use `colored-text` output format can now decide if they want the timestamp or can rely on their server/cloud environments info.
This commit is contained in:
Gabriel Grubba
2025-02-12 07:58:47 -03:00
parent 9e5396ed3f
commit a70ac879fe

View File

@@ -44,6 +44,11 @@ Log._intercepted = () => {
// other process that will be reading its standard output.
Log.outputFormat = 'json';
// Defaults to true for local development and for backwards compatibility.
// for cloud environments is interesting to leave it false as most of them have the timestamp in the console.
// Only works in server with colored-text
Log.shouldShowTime = true;
const LEVEL_COLORS = {
debug: 'green',
// leave info as the default color
@@ -296,13 +301,15 @@ Log.format = (obj, options = {}) => {
const stderrIndicator = stderr ? '(STDERR) ' : '';
const timeString = Log.shouldShowTime
? `${dateStamp}-${timeStamp}${utcOffsetStr}${timeInexact ? '? ' : ' '}`
: ' ';
const metaPrefix = [
level.charAt(0).toUpperCase(),
dateStamp,
'-',
timeStamp,
utcOffsetStr,
timeInexact ? '? ' : ' ',
timeString,
appInfo,
sourceInfo,
stderrIndicator].join('');