Skip to content
Compare
Choose a tag to compare
@trilom trilom released this 22 Apr 17:40
cd99906

🪵 Log

make logging grape again with color

Simple

import { Log, random as r } from "https://deno.land/x/trailmix@1.0.5/mod.ts";
Log.error("basic britches👖"); // in red "[default] basic britches👖"
// pass any number of arguments
Log.success(
  "test",
  { error: "really?" },
  "s",
  20,
  90071992547409990071992547404545990n,
  true,
  null,
  undefined,
  Symbol("key"),
  new Error("test"),
  Log.success("noArgs"),
  Log.error("args", "failure"),
); // in green  "[default] success"
Log.error("error", "trust me, its 👌"); //
Log.success(
  "silly " + r("r") + r("a") + r("n") + r("d") + r("o") + r("m") + " strang",
);
goofus_log goofus log trailmix deno typescript

Complex

import {
  EnvConfig,
  FlagConfig,
  Log,
} from "https://deno.land/x/trailmix@1.0.5/mod.ts";

// make a logger with flags
const l = await new Log(
  "default",
  new FlagConfig({
    flags: {
      logConsoleLevel: "DEBUG",
      logConsoleFormat: "json",
      logFileEnabled: true,
      logFilePath: ".",
      logFileLevel: "DEBUG",
      logFileFormat: "string",
    },
  }).log,
).init();
// now log, 5 console json messages, and 5 string file messages
l.success("success");
l.error("error");
l.warn("warn");
l.info("info");
l.debug("debug");

// make a test logger with env for deDEBUG
Deno.env.set("DEFAULT_LOG_CONSOLE_LEVEL", "DEBUG");
const lNew = await new Log(
  "test",
  new EnvConfig().log,
).init();
// now log, 6 console string messages
lNew.success("success");
lNew.error("error");
lNew.warn("warn");
lNew.info("info");
lNew.debug("debug");
goofus_log goofus log trailmix deno typescript