log_docs
v1.0.1
Published
Log Docs is a TypeScript package that provides logging functionality for documenting activities in your application. It allows you to connect to a MongoDB database and log various events with customizable details.
Downloads
1
Readme
Log Docs (TypeScript)
Log Docs is a TypeScript package that provides logging functionality for documenting activities in your application. It allows you to connect to a MongoDB database and log various events with customizable details.
Installation
To use Log Docs in your TypeScript project, you need to install it using npm:
npm install log_docs
Usage
Import the logger
module from log_docs
in your TypeScript file:
import * as logger from 'log_docs';
Environment Variables
The following environment variables are used by Log Docs:
DATABASETYPE
: Specifies the type of database to connect to (e.g., "mongodb").EXPIRE_SEC
: Sets the number of seconds after which database records should be deleted.
Make sure to configure these environment variables before using the logger.
Logging Functions
Connect to the Database
To establish a connection to the MongoDB database, use the following syntax:
logger.connect(connectionString: string);
Replace connectionString
with the appropriate connection string for your MongoDB database.
Log Activity
To log an activity, use the activity
function with the following parameters:
logger.activity(
key: string,
event: string,
sub_event: string,
event_response: string,
event_status: string
);
key
: A unique identifier for the activity.event
: The main event being logged.sub_event
: A sub-event or additional information related to the main event.event_response
: The response or result of the event.event_status
: The status of the event (e.g., success, failure).
Example
Here's an example of how to use Log Doc in a TypeScript project:
import * as logger from 'log_docs';
logger.connect('mongodb://localhost:27017/mydatabase');
logger.activity(
'123456',
'User Login',
'Authentication',
'Login successful',
'Success'
);
This will log a successful user login activity in the connected MongoDB database.
Remember to configure the appropriate environment variables and ensure that your MongoDB server is running before using the logger.
For further information or support, please refer to the package documentation or contact the package author.