Skip to the content.

yalo.js

Yet Another Logger

NPM Version NPM Unpacked Size NPM License

const yalo = require("yalo.js")
const logger = yalo.createLogger("output.log")

logger.info("Hello, World!")
logger.error("Error occurred")

Installation

npm install yalo.js

No dependencies required

Usage

// configuration
const options = {
    depth: 2,
    errors: {
        title: "Error",
        format: ["=", "-"],
        width: 36
    }
}

// logger instance
const logger = yalo.createLogger("output.log", options)

// deeply nested object
const object = { a: { b: { c: { d: 0 } } } }

// logs an info message
logger.info(object, "\n")

// removes depth limit
logger.depth = null

// logs full `object`
logger.info(object)

// error() examples
const a = undefined
const b = 0
const c = 36

// options.errors.title
if (!a) logger.error(`a is ${a}`)

// custom title
if (b < 1) logger.error(`b is less than 1`, "Warning")

// dynamic title
if (c > 24) logger.error(`c is more than 24`, () => `c: ${c}`)

logger.info("Hello again!\n")

// used in loops
logger.end()

Output:

{ a: { b: { c: [Object] } } }

{
  a: { b: { c: { d: 0 } } }
}

============== Error ==============

 a is undefined

-----------------------------------


============= Warning =============

 b is less than 1

-----------------------------------


============== c: 36 ==============

 c is more than 24

-----------------------------------

Hello again!

Reference

createLogger(dest, options?)

createLogger(
	dest: string,
	options?: Partial<{
		depth: number | null
		errors: Partial<{
			title: string | Function
			format: string[]
			width: number
			errorMode: boolean
		}>
	}>
)

@returns

{
	fileStream: fs.WriteStream
	depth: number | null
	errors: {
		title: string | Function
		format: string[]
		width: number
		errorMode: boolean
	}
	info(...data: any[]): void
	error(data: any, title?: string | Function): void
	end(): void
}

info(data)

info(...data: any[]): void

error(data, title?)

error(data: any, title?: string | Function): void

end()

end(): void

options.errors.errorMode

{
    errors: {
        errorMode: true
    }
}

Examples

Error logger with Date()

const options = {
    errors: {
        title: () => new Date(),
        errorMode: true
    }
}

const logger = yalo.createLogger("error.log", options)

try {
    // ...
} catch (error) {
    logger.error(error)
}

License

MIT


Made for the Transmoder project