1.6.1 โ€ข Published 7 months ago

@odg/log v1.6.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

codecov Stargazers Made by ODGodinho Forks Repository size GitHub last commit License StyleCI

Table of Contents


๐ŸŽ‡ Benefits

  • ๐Ÿš€ Logs Pattern interface
  • ๐Ÿšจ Similar PHP psr-3

๐Ÿ“— Libraries

๐Ÿ“ Dependencies

โฉ Get Started


๐Ÿ”˜ Use Log Interface

Install in your project using this command

yarn add @odg/log

๐Ÿ“ฐ Usage

๐Ÿ“ฐ Exception

InvalidArgumentException dispatch if send invalid arguments

๐ŸŒŽ Implementation

  • LoggerAwareInterface Implements this if your class dependencies Logger
  • LogLevel it is an enum with the types of logs
  • LogLevelType is a list of log types
  • LoggerInterface for create a logger class
  • AbstractLogger Abstract class to logger implements only log function
  • NullLogger Generic logger without action

๐Ÿฐ Free Sample

๐Ÿ”‰ Class Aware Log

If you class dependencies LoggerInstance use interface LoggerAwareInterface

if you prefer you can depend on the log class in your constructor

import { LoggerAwareInterface, LoggerInterface } from "@odg/log";

export class LoggerAwareExample implements LoggerAwareInterface {

    private logger?: LoggerInterface;

    public setLogger(logger: LoggerInterface): void {
        this.logger = logger;
    }

    public runExampleClass(): void {
        try {
            // Anything code
        } catch (error) {
            this.logger?.debug(error);
        }
    }

}

๐Ÿ‘€ Create Logger Class

/**
 * This Example Logger using console.log
 *
 * @author Dragons Gamers <https://github.com/ODGodinho>
 */
export class ConsoleLogger extends AbstractLogger {

    /**
     * Logs with an arbitrary level.
     *
     * @param {LogLevel} level Log level
     * @param {unknown} message Message Log
     * @param {TContext} context Context Message replace
     *
     * @returns {Promise<void>}
     */
    public async log(level: LogLevel, message: unknown, context?: TContext): Promise<void> {
        const log = await this.parser(level, message, context); // Use this for plugins load

        return console.log(`Level: ${log.level} >> ${String(log.message)}`, log.context);
    }

}

๐Ÿ’ป Prepare To Develop

Copy .env.example to .env and add the values according to your needs.

๐Ÿ“ Start Project

First install dependencies with the following command

yarn install
# or
npm install

๐Ÿ“จ Build and Run

To build the project, you can use the following command

if you change files, you need to run yarn build and yarn start again

yarn build && yarn start
# or
yarn dev

๐Ÿงช Teste Code

To Test execute this command

yarn test
# or
yarn test:watch
1.6.1

7 months ago

1.6.0

7 months ago

1.5.1

8 months ago

1.4.2

8 months ago

1.5.0

8 months ago

1.4.1

8 months ago

1.4.0

8 months ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.3.0

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago