New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

white-logger

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

white-logger

a very simple browser and node logger with only one dependency

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

white-logger

A very simple nodejs and browser logger with only one dependency.

feature

  • Only one dependency. Use Luxon for dealing with dates and times.
  • Pretty print.
  • Native TypeScript.
  • Circular safe.

install

npm i white-logger

useage

nodejs

use typescript or ESM

import { nodelogger as logger } from "white-logger/node";

logger.nomal("nomal-level", "normal reported.");
logger.info("info here", "something reported.", {
  hello: "world",
});
logger.warn("notice", "something warnning.", ["foo", "baz"]);
logger.err("oops!", "something error!");

You will get like this in your console.

log preview img

You can also give __filename to the second parameter to get relative path output from your project root dir.

import { nodelogger as logger } from "white-logger/node";

logger.info("some info", __filename, "i am here!");

And you will get like this. Easy to find out the problem, right?

filename preview img

By default, white-logger does not write log to files. If you want to do this, please configure some setting like this.

import { nodelogger as logger, configLogger } from "white-logger/node";
import path from "path";

// By setting the logPath option, white-logger will write the log to files automatically.
configLogger({
  logPath: path.resolve(process.cwd(), "logs"),
});

// Will be written to <project_root>/logs/<timestamp>_info.log
logger.info("some-info", "something reported.");

Depending on the level, the logs will be written to different files.

  • logger.nomal will write to <timestamp>_nomal.log
  • logger.info will write to <timestamp>_info.log
  • logger.warn will write to <timestamp>_warn.log
  • logger.err will write to <timestamp>_err.log

Timestamp will change from day to day. So, the logs are output to a different file each day.

You can also only pass a relative path, white-logger will resolve it to your project root directory automatically.

configLogger({
  // Same as above, logs will write to <project_root_dir>/logs
  logPath: "logs",
});

use CommonJS

const { nodelogger } = require("white-logger/node");

nodelogger.nomal("nomal-level", "normal reported.");

You can also import with a name of your choice.

const mylogger = require("white-logger/node").nodelogger;

mylogger.nomal("nomal-level", "normal reported.");

browser

You can use white-logger in any framework. Like vue or react.

// Please note that the esm module is in esm directory.
import { browserlogger as logger } from "white-logger/esm/browser";

logger.nomal("nomal-level", "normal reported.");
logger.info("info here", "something reported.", {
  hello: "world",
});
logger.warn("notice", "something warnning.", ["foo", "baz"]);
logger.err("oops!", "something error!");

Open your console and you can see the results.

browser preview img

configuration

export type white-loggerConfig = {
  logPath: string | undefined; // full or relative path to your logs directory
  logDateFmt: string; // Luxon fmt string
  filenameDateFmt: string; // Luxon fmt string
};

// default value
let __config__: white-loggerConfig = {
  logPath: undefined,
  logDateFmt: "yyyy'-'LL'-'dd HH'-'mm'-'ss Z",
  filenameDateFmt: "yyyy'-'LL'-'dd",
};

About Luxon fmt string, please see this Luxon document

  • logPath The path of directory that white-logger will write log to.
  • logDateFmt The format of the date being printed to the console.
  • filenameDateFmt The format of the date before being inserted into the output file.

Why is it call White logger?

"Any color you want, so long as it is Black."

So, White logger.

Keywords

FAQs

Package last updated on 14 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc