@ao-framework/logger

The logger is an abstract class that allows you to create custom loggers where you can define a specific implementation without having to worry about specific methods commonly used in the practice of logging information in applications.

Usage no npm install needed!

<script type="module">
  import aoFrameworkLogger from 'https://cdn.skypack.dev/@ao-framework/logger';
</script>

README


Logger

The logger is an abstract class that allows you to create custom loggers where you can define the functionality implementation without having to worry about implementing commonly used methods in the practice of logging information. It provides for both sync and async functionality.

Import the library

import Logger from "@ao-framework/logger";

Create a Logger

export class MyLogger extends Logger {

    protected async implementation(level: string, message: string) {
        //do something with your message
    }

    protected implementationSync(level: string, message: string) {
        //do something with your message
    }

}

export default new MyLogger();

Use it

import mylogger from "./loggers/mylogger"

//either below will work
mylogger.info(`This is a log message for ${user.name}`)
mylogger.info("This is a log message for ${user.name}", user)

Available Methods

logger.emergency(message: string, context?: object) => Promise<any> 
//or
logger.emergencySync(message: string, context?: object) => any 
logger.alert(message: string, context?: object) => Promise<any>
//or 
logger.alertSync(message: string, context?: object) => any 
logger.critical(message: string, context?: object) => Promise<any> 
//or
logger.criticalSync(message: string, context?: object) => any
logger.error(message: string, context?: object) => Promise<any> 
//or
logger.errorSync(message: string, context?: object) => any 
logger.warning(message: string, context?: object) => Promise<any> 
//or
logger.warningSync(message: string, context?: object) => any 
logger.notice(message: string, context?: object) => Promise<any> 
//or
logger.noticeSync(message: string, context?: object) => any 
logger.info(message: string, context?: object) => Promise<any> 
//or
logger.infoSync(message: string, context?: object) => any 
logger.debug(message: string, context?: object) => Promise<any> 
//or
logger.debugSync(message: string, context?: object) => any 
logger.log(level: string, message: string, context?: object) => Promise<any> 
//or
logger.logSync(level: string, message: string, context?: object) => any