- ๐ Benefits
- ๐ Libraries
- ๐ Dependencies
- โฉ Get Started
- ๐ฐ Usage
- ๐ฐ Free Sample
- ๐ป Prepare to develop
- ๐ Logs Pattern interface
- ๐จ Similar PHP psr-3
- Node.js 16 or later
- Yarn Optional/Recommended
- ODG TsConfig Last Version
- ODG Exception
Install in your project using this command
yarn add @odg/log
InvalidArgumentException dispatch if send invalid arguments
- 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
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);
}
}
}
/**
* 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);
}
}
Copy .env.example
to .env
and add the values according to your needs.
First install dependencies with the following command
yarn install
# or
npm install
To build the project, you can use the following command
if you change files, you need to run
yarn build
andyarn start
again
yarn build && yarn start
# or
yarn dev
To Test execute this command
yarn test
# or
yarn test:watch