Skip to content

Releases: trailmix/utilities

log

22 Apr 17:40
cd99906
Compare
Choose a tag to compare

🪵 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

config

02 Apr 00:49
13ad956
Compare
Choose a tag to compare

config

goofus_config goofus config trailmix deno typescript

Simple

import { EnvConfig, StringConfig } from "https://deno.land/x/trailmix@1.0.4/mod.ts";

Deno.env.set("DEFAULT_TEST1", "val1"); // set example env var in DEFAULT namespace
// slurp up env vars
console.log(EnvConfig.parseEnv()); // should have { test1: "val1" }
// something more complex
Deno.env.set("DEFAULT_CONSOLE_LEVEL", "DEBUG"); // set log level in DEFAULT namespace
console.log(EnvConfig.parseEnv()); // should have { test1: "val1", console: { level: "DEBUG" } }
// this is good for cmd line arguments (--consoleLevel DEBUG)
console.log(StringConfig.parseEnv({ test1: "val1", consoleLevel: "DEBUG" })); // should have same as above

Complex

import { Config, EnvConfig, StringConfig } from "https://deno.land/x/trailmix@1.0.4/mod.ts";

// lets use our own namespace with a config file
const c = await new Config({
  namespace: "TRAILMIX",
  prefix: "trailmixString.config",
}).init();
// inside trailmixString.config.ts/tsx
export default {
  consoleFormat: "json",
};
console.log(new StringConfig(c).parseLog()); // will give a log config with {console: { format: "json" } }
// now lets take into account env vars
Deno.env.set("TRAILMIX_CONSOLE_FORMAT", "console");
console.log(new EnvConfig(c).parseLog()); // will give a log config with {console: { format: "console" } }

🏴‍☠️🎲🧬

23 Mar 06:27
46719d1
Compare
Choose a tag to compare

colors

  • adding types

🏴‍☠️🎲

22 Mar 16:01
e4b8378
Compare
Choose a tag to compare

Colors:

  • Adding randomOpts() function
  • Fix some import issues.

🏴‍☠️

22 Mar 05:47
4ac829c
Compare
Choose a tag to compare
1.0.1

pkg.json

init

22 Mar 05:33
4b8b0d2
Compare
Choose a tag to compare
1.0.0

plez