mirror of
https://github.com/HeyPuter/puter.git
synced 2026-10-05 03:18:30 +00:00
devex: show full time in dev log output
This commit is contained in:
@@ -21,6 +21,7 @@ const { AdvancedBase } = require("@heyputer/putility");
|
||||
const EmitterFeature = require("@heyputer/putility/src/features/EmitterFeature");
|
||||
const { Context } = require("./util/context");
|
||||
const { ExtensionServiceState } = require("./ExtensionService");
|
||||
const { display_time } = require("@heyputer/putility/src/libs/time");
|
||||
|
||||
/**
|
||||
* This class creates the `extension` global that is seen by Puter backend
|
||||
@@ -281,7 +282,7 @@ class Extension extends AdvancedBase {
|
||||
get console () {
|
||||
const extensionConsole = Object.create(console);
|
||||
extensionConsole.log = (...a) => {
|
||||
console.log(`\x1B[${this.terminal_color};1m(extension/${this.name})\x1B[0m`, ...a);
|
||||
console.log(`${display_time(new Date())} \x1B[${this.terminal_color};1m(extension/${this.name})\x1B[0m`, ...a);
|
||||
};
|
||||
return extensionConsole;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,15 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const log_epoch = Date.now();
|
||||
const { display_time, module_epoch } = require('@heyputer/putility/src/libs/time.js');
|
||||
const config = require('../../../config.js');
|
||||
|
||||
// Example:
|
||||
// log("booting"); // → "14:07:12 booting"
|
||||
// (next day) log("tick"); // → "16 00:00:01 tick"
|
||||
// (next month) log("tick"); // → "11-01 00:00:01 tick"
|
||||
// (next year) log("tick"); // → "2026-01-01 00:00:01 tick"
|
||||
|
||||
|
||||
/**
|
||||
* Stringifies a log entry into a formatted string for console output.
|
||||
@@ -39,18 +47,26 @@ const stringify_log_entry = ({ prefix, log_lvl, crumbs, message, fields, objects
|
||||
if ( ! m ) return;
|
||||
lines.push(m);
|
||||
m = '';
|
||||
};
|
||||
|
||||
m = '';
|
||||
|
||||
if ( ! config.show_relative_time ) {
|
||||
m += `${display_time(fields.timestamp)} `;
|
||||
}
|
||||
|
||||
m = prefix ? `${prefix} ` : '';
|
||||
m += prefix ? `${prefix} ` : '';
|
||||
m += `\x1B[${log_lvl.esc}m[${log_lvl.label}\x1B[0m`;
|
||||
for ( const crumb of crumbs ) {
|
||||
m += `::${crumb}`;
|
||||
}
|
||||
m += `\x1B[${log_lvl.esc}m]\x1B[0m`;
|
||||
if ( fields.timestamp ) {
|
||||
// display seconds since logger epoch
|
||||
const n = (fields.timestamp - log_epoch) / 1000;
|
||||
m += ` (${n.toFixed(3)}s)`;
|
||||
if ( config.show_relative_time ) {
|
||||
// display seconds since logger epoch
|
||||
const n = (fields.timestamp - module_epoch) / 1000;
|
||||
m += ` (${n.toFixed(3)}s)`;
|
||||
}
|
||||
}
|
||||
m += ` ${message} `;
|
||||
lf();
|
||||
@@ -69,5 +85,4 @@ const stringify_log_entry = ({ prefix, log_lvl, crumbs, message, fields, objects
|
||||
|
||||
module.exports = {
|
||||
stringify_log_entry,
|
||||
log_epoch,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user