This package has been deprecated

Author message:

outdated

@sumor-cloud/logger

1.0.5 • Public • Published

@sumor-cloud/logger

Sumor Logger aims to provide a universal logging format, color differentiation, cross-time zone, multi-language, and highly scalable logging interface.

NPM version NPM downloads

A Sumor Cloud Tool.
More Documentation

Installation

npm install -D @sumor-cloud/logger

Usage

General Usage

import Logger from '@sumor-cloud/logger';
const logger = new Logger();

logger.trace("Hello World!");
// You will see the following output:
// 2020-01-01 00:00:00.000 TRACE MAIN - Hello World!

Change Scope

For some case, we need categorize logs. scope is used for this purpose.

import Logger from '@sumor-cloud/logger';
const logger = new Logger({
    scope: 'DEMO'
});
logger.trace("Hello World!");
// You will see the following output:
// 2020-01-01 00:00:00.000 TRACE DEMO - Hello World!

Identifier User

For some case, we need identifier user. id is used for this purpose.

import Logger from '@sumor-cloud/logger';
const logger = new Logger({
    id: 'USER001'
});
logger.trace("Hello World!");
// You will see the following output:
// 2020-01-01 00:00:00.000 TRACE MAIN USER001 - Hello World!

Change Level

Most of the time, we only need to output logs of a certain level. Then we can decide if store and display it or not.

import Logger from '@sumor-cloud/logger';
const logger = new Logger();
logger.trace("Hello World!"); // trace is the lowest level, all logs will be output
logger.debug("Hello World!");
logger.info("Hello World!");
logger.warn("Hello World!");
logger.error("Hello World!");
logger.fatal("Hello World!"); // fatal is the highest level, only critical error will be output

Enable Translation

import Logger from '@sumor-cloud/logger';
const logger = new Logger({
    i18n:{
        "SAY_HELLO":"Hello, {user}"
    }
});
logger.info("SAY_HELLO",{user:"Sumor"});
// You will see the following output:
// 2020-01-01 00:00:00.000 INFO MAIN - Hello, Sumor

Change Timezone

import Logger from '@sumor-cloud/logger';
const logger1 = new Logger({
    offset: 2 * 60 // UTC+2 offset is 2 hours
});
logger1.info("Hello World!");
// You will see the following output:
// 2020-01-01 02:00:00.000 INFO MAIN - Hello World!

const logger2 = new Logger({
    offset: 8 * 60 // UTC+8 offset is 8 hours
});
logger2.info("Hello World!");
// You will see the following output:
// 2020-01-01 08:00:00.000 INFO MAIN - Hello World!

Save Logs

Usually, we need to save logs to a file. We can add saver to the logger.

import Logger from '@sumor-cloud/logger';
import fs from 'fs';
const logger = new Logger({
    saver: (message) => {
        // save message to file
        fs.appendFileSync('main.log', message);
    }
});

Load Logs

Sometimes, you may need to load logs from a file. We can use load method to resume the logs. And also, you can use this to switch log language as well by passing different i18n.

import Logger from '@sumor-cloud/logger';
const logger = new Logger({
    i18n:{
        "SAY_HELLO":"Morning, {user}"
    }
});
logger.load(`# [2020-01-01T00:00:00.000Z] [INFO] [MAIN] - SAY_HELLO | {"user":"Sumor"}`);
// You will see the following output:
// 2020-01-01 00:00:00.000 INFO MAIN - Morning, Sumor

Contributing & Issues

You can use this tool for free.
But we are a commercial company, to ensure stability, we currently don't offer a joint contribution mechanism.
You can report issues through Report Library Issue Ticket, and we will fix them as soon as possible.

License

In consideration of the chaotic situation in the open source community, we provide obfuscated code for use and security analysis.
However, we do not provide the source code in its original form in order to protect the ongoing maintenance and creative interests and motivations.
The released code in NPMJS is based on MIT. The source code is closed-source.

Our tools are free to use in order to help build cloud applications more efficiently. Our commercial purpose is to improve the ecosystem of business websites.
If there are any innovations that greatly benefit the open source community, it will be separated and contributed to the open source community.

Versions

Current Tags

VersionDownloads (Last 7 Days)Published

Version History

VersionDownloads (Last 7 Days)Published

Package Sidebar

Install

npm i @sumor-cloud/logger

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

8.07 kB

Total Files

3

Last publish

Collaborators

  • ohnow