Releases: trailmix/utilities
Releases · trailmix/utilities
log
🪵 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",
);
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");
config
config
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" } }