Skip to content

Rubiks is a 0 dependency extendable logging library for modern applications.

License

Notifications You must be signed in to change notification settings

rubiksjs/rubiks

Repository files navigation

Rubiks


JSR deno module

Rubiks is a 0 dependency extendable logging library for modern applications.

import { rubiks, warn, withDates } from "@rubiks/rubiks";

rubiks()
    .log("Rubiks can do normal logging")
    .log("Rubiks can also use custom levels, which allow changing the action", warn)
    .warn("It also has some included methods for simplicity")
    .use(withDates)
    .log("You can also use modifiers, that modify all logs of this instance");

Levels

Levels allow you to change the log, it can change the format, save logs to files, basically everything you can code!

import { rubiks } from "@rubiks/rubiks";

// `self` is a reference to the rubiks instance where it's use (basically a cleaner way to use this)
// `content` is the string that the user will pass to the log function
function customLevel(self, content) {
    console.log(`This is the content: ${content}`)
}

rubiks()
    .log("hello!", customLevel)

Modifiers

Modifiers modify every log of the rubiks instance. There are a couple of modifiers built-in into rubiks, but you can also create your own modifiers

import { rubiks } from "@rubiks/rubiks";

function myCustomModifier(self) {
    // The code outside of the returned function only gets executed once, on use.
    self.format = self.format.toLowerCase()

    // As you may see, this function is a level, Modifiers return levels that get executed in every log
    return (self, content) => {
        // The code inside of this function gets executed on every log
        self.format += `${content} `
    }
}

rubiks()
    .use(myCustomModifier)
    .log("testing")
    .error("more")