<commit_before>/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */

declare var window;

import { RUNNING_IN_NODE, seconds2hms } from "./misc";

let smc_logger_timestamp, smc_logger_timestamp_last, smc_start_time;
smc_logger_timestamp = smc_logger_timestamp_last = smc_start_time =
  new Date().getTime() / 1000.0;

export const get_start_time_ts = () => new Date(smc_start_time * 1000);

export const get_uptime = () =>
  seconds2hms(new Date().getTime() / 1000.0 - smc_start_time);

export function log(..._args): void {
  smc_logger_timestamp = new Date().getTime() / 1000.0;
  const t = seconds2hms(smc_logger_timestamp - smc_start_time);
  const dt = seconds2hms(smc_logger_timestamp - smc_logger_timestamp_last);
  // support for string interpolation for the actual console.log
  const [msg, ...args] = Array.from(Array.prototype.slice.call(arguments));
  let prompt = `[${t} Δ ${dt}]`;
  if (typeof msg == "string") {
    prompt = `${prompt} ${msg}`;
    (console as any).log_original(prompt, ...Array.from(args));<commit_msg>add ISO timestamp to client console log<commit_after>/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */

declare var window;

import { RUNNING_IN_NODE, seconds2hms } from "./misc";

let smc_logger_timestamp, smc_logger_timestamp_last, smc_start_time;
smc_logger_timestamp =
  smc_logger_timestamp_last =
  smc_start_time =
    new Date().getTime() / 1000.0;

export const get_start_time_ts = () => new Date(smc_start_time * 1000);

export const get_uptime = () =>
  seconds2hms(new Date().getTime() / 1000.0 - smc_start_time);

export function log(..._args): void {
  smc_logger_timestamp = new Date().getTime() / 1000.0;
  const t = seconds2hms(smc_logger_timestamp - smc_start_time);
  const dt = seconds2hms(smc_logger_timestamp - smc_logger_timestamp_last);
  // support for string interpolation for the actual console.log
  const [msg, ...args] = Array.from(Array.prototype.slice.call(arguments));
  let prompt = `[${t} Δ ${dt} - ${new Date().toISOString()}]`;
  if (typeof msg == "string") {
    prompt = `${prompt} ${msg} ${new Date()}`;
    (console as any).log_original(prompt, ...Array.from(args));
{'fraction_non_alphanumeric': 0.13941480206540446, 'fraction_numerical': 0.024096385542168676, 'mean_word_length': 4.4834905660377355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4705893', 'n_tokens_mistral': 852, 'n_tokens_neox': 801, 'n_words': 203}