namirasoft-log v1.3.16
Namirasoft TS SDK Log
Namira Software Corporation Log Package is a powerful Node.js library designed to simplify the management of logging, error handling, and notifications within your applications. With a focus on flexibility and extensibility, this library empowers developers to effortlessly control how their applications log information, handle errors, and send notifications across various channels such as Telegram, email, SMS, and push notifications. Whether you need to track critical events, respond to unhandled exceptions, or deliver real-time alerts to different stakeholders, it provides a robust solution with a straightforward API. Customize the behavior to suit your unique use case and seamlessly integrate it into your projects to enhance both monitoring and communication capabilities. Streamline your development workflow and enhance the reliability of your applications with Namira Software Corporation Log Package. Namira Software Corporation
Features
This library provides the following key features:
- Logging: Log messages to various sources such as the console, files, database and Namirasoft Log Server
- Error Handling: Catch all unhandled errors in your Node.js application.
- Notifications: Send messages and alerts through different media (Email, SMS, Telegram, push notifications, and etc.) based on configurable conditions. You can find more here Namirasoft Log Server
You can customize the library's behavior and integrate it with various notification platforms to suit your specific use case.
Installation
npm install namirasoft-log
Import
First you need to import it.
- JavaScript
```js let Logger = require("namirasoft-log"); ```
- TypeScript
```js import { Logger } from "namirasoft-log"; ```
Make a Logger
To make a logger please use this:
- JavaScript
```js let logger = new Logger(); ```
- TypeScript
```js let logger: Logger = new Logger(); ```
Usage
Normal Logging
logger.trace("This is a test for trace");
logger.verbose("This is a test for verbose");
logger.debug("This is a test for debug");
logger.info("This is a test for info");
logger.warning("This is a test for warning");
logger.error("This is a test for error");
logger.critical("This is a test for critical");
logger.fatal("This is a test for fatal");
Grouping Logs
logger.error("Out of stuck", "Payment");
logger.error("Can not find your account", "Account");
logger.warning("You account is not verified yet.", "Account");
logger.Info("Invoice has been paid successfully", "Payment");
Extra and Stack information
logger.debug("message", "group", "More details go here");
logger.error("message", "group", "More details go here");
logger.warning("message", "group", "More details go here");
logger.fatal("message", "group", "More details go here");
Loggin errors on catch
try
{
// some bad codes here making error
}
catch(e)
{
logger.onCatchError(e);
}
try
{
// some bad codes here making error
}
catch(e)
{
logger.onCatchCritical(e);
}
try
{
// some bad codes here making error
}
catch(e)
{
logger.onCatchFatal(e);
}
Error Handling
To handle all unhandled exceptions on the entire project:
logger.initUncought();
Streams
Console
To add a stream on console which is the default stream use:
import { StreamConsole } from "namirasoft-node";
logger.addStream(new StreamConsole());
File
To add a stream on file:
import { StreamFile} from "namirasoft-node";
let streamFile = new StreamFile("Your-Custom-Path"); // your can pss "" for argument
streamFile.seprateByDate = true; // this is the default value
streamFile.seprateByGroup = false; // this is the default value
streamFile.seprateByLevel = true; // this is the default value
logger.addStream(streamFile);
Namirasoft Log
To add a stream on Namirasoft Log API which gives which is the default stream use:
import { StreamNamirasoftLog } from "namirasoft-node";
logger.addStream(new StreamNamirasoftLog("Your-Token"));
You can get your token Here after creating your account and project.
Custom
It is also possible to create custom stream like for database:
fist create your custom class like
import { IStream } from "./IStream";
import { Log } from "./Log";
import { LogLevel } from './LogLevel';
export class MyCustomStream implements IStream
{
async write(log: Log, formated: string[]): Promise<void>
{
// save log or formated
}
}
Then add it to your logger
logger.addStream(new MyCustomStream());
You can get your token Here after creating your account and project.
Formatters
Full
To set a full formatter which is the default formatter use:
import { FormatterFull } from "namirasoft-node";
logger.setFromatter(new FormatterFull());
Short
To set a short formatter use:
import { FormatterShort } from "namirasoft-node";
logger.setFromatter(new FormatterShort());
Level-Based
To set a different formatter for each Log Level use:
import { LogLevel, FormatterShort, FormatterFull } from "namirasoft-node";
logger.setCustomFormatter(LogLevel.Info, new FormatterShort());
logger.setCustomFormatter(LogLevel.Error, new FormatterFull());
Custom
To make a custom formatter make a formatter class like:
import { BaseFormatter, IFormatter, Log } from "namirasoft-node";
export class MyCustomFormatter extends BaseFormatter implements IFormatter
{
async format(log: Log): Promise<string[]>
{
let ans: string[] = [];
ans.push(this.formatDateTime(log.date) + ": " + log.message);
return ans;
}
}
Then add it to your logger
logger.addStream(new MyCustomFormatter());
5 days ago
5 days ago
8 days ago
8 days ago
7 days ago
7 days ago
7 days ago
7 days ago
8 days ago
8 days ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago