Skip to content

Commit

Permalink
logger added
Browse files Browse the repository at this point in the history
  • Loading branch information
siva-sparkout committed Aug 1, 2023
1 parent ba89954 commit 61322b8
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 9 deletions.
128 changes: 128 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
mohdsamgankhan@gmail.com.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
53 changes: 53 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Contributing to Transcriptase
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features
- Becoming a maintainer

## We Develop with Github
We use github to host code, to track issues and feature requests, as well as accept pull requests.

## We Use [Github Flow](https://docs.github.com/en), So All Code Changes Happen Through Pull Requests
Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://docs.github.com/en)). We actively welcome your pull requests:

1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. Issue that pull request!

## Any contributions you make will be under the MIT Software License
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.

## Report bugs using Github's [issues](https://github.com/msamgan/expressjs-api-boilerplate/issues/new)
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy!

## Write bug reports with detail, background, and sample code
[This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report I wrote, and I think it's not a bad model. Here's [another example from Craig Hockenberry](http://www.openradar.me/11905408), an app developer whom I greatly respect.

**Great Bug Reports** tend to have:

- A quick summary and/or background
- Steps to reproduce
- Be specific!
- Give sample code if you can. [My stackoverflow question](http://stackoverflow.com/q/12488905/180626) includes sample code that *anyone* with a base R setup can run to reproduce what I was seeing
- What you expected would happen
- What actually happens
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)

People *love* thorough bug reports. I'm not even kidding.

## Use a Consistent Coding Style
I'm again borrowing these from [Facebook's Guidelines](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)

* 4 spaces for indentation rather than tabs

## License
By contributing, you agree that your contributions will be licensed under its MIT License.

## References
This document was adapted from the open-source contribution guidelines for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)
9 changes: 9 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Security Policy

## Supported Versions

All Versions are supported for Security Updates.

## Reporting a Vulnerability

Please report any security concern on **gotocva@gmail.com**
3 changes: 2 additions & 1 deletion skeletons/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
node_modules/
dist/
coverage/
coverage/
logs/
1 change: 1 addition & 0 deletions skeletons/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@route/*": ["src/routes/*"],
"@util/*": ["src/utils/*"],
"@validator/*": ["src/validators/*"],
"@log/*": ["src/logger/*"],
}
},
"exclude": ["node_modules", "dist"]
Expand Down
14 changes: 12 additions & 2 deletions skeletons/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions skeletons/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "express-rest-boilerplate",
"name": "{NAME}",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand All @@ -11,7 +11,7 @@
"lint": "eslint src"
},
"keywords": [],
"author": "something",
"author": "sivabharathy",
"license": "MIT",
"_moduleAliases": {
"@root": ".",
Expand All @@ -21,6 +21,7 @@
"@middleware": "dist/middlewares",
"@model": "dist/models",
"@route": "dist/routes",
"@log": "dist/logger",
"@util": "dist/utils",
"@validator": "dist/validators"
},
Expand All @@ -35,6 +36,7 @@
"module-alias": "^2.2.3",
"moment": "^2.29.4",
"mongoose": "^7.3.1",
"nila-logger": "^1.0.2",
"node-telegram-bot-api": "^0.61.0",
"nodemailer": "^6.9.3",
"socket.io": "^4.7.0",
Expand Down
2 changes: 2 additions & 0 deletions skeletons/src/config/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ export const appConfig = {

API_RATE_LIMIT_TIME : 15, // 15 minutes
API_RATE_LIMIT : 100, // 100 requests for every 15 minutes

LOG_DIRECTORY: 'logs',
}

7 changes: 4 additions & 3 deletions skeletons/src/database/mongoose.db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mongoose from 'mongoose';
import { dbConfig } from '@config/db.config';
import { LOG } from '@log/index';

/**
* @author sivabharathy
Expand All @@ -14,18 +15,18 @@ export const connectDB = () => {

// when successfully connected
mongoose.connection.on('connected', () => {
console.log('Mongodb successfully connected');
LOG.info('Mongodb successfully connected');
});

// if the connection throws an error
mongoose.connection.on("error", (err) => {
// if you get error for the first time when this gets started make sure to run mongodb
console.log('Mongodb connection failed', err);
LOG.info('Mongodb connection failed', err);
});

// when the connection is disconnected
mongoose.connection.on("disconnected", () => {
console.log('Mongodb disconnected');
LOG.error('Mongodb disconnected');
});

return mongoose.connection;
Expand Down
3 changes: 2 additions & 1 deletion skeletons/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { connectDB } from './database/mongoose.db';
import { routeLoader } from './routes';
import { appConfig } from '@config/app.config';
import { app } from './express';
import { LOG } from '@log';

export const mongooseConnection = connectDB();

Expand All @@ -12,5 +13,5 @@ export const application = routeLoader(app);
const http = createServer(application);

http.listen(process.env.PORT || appConfig.PORT || 8080, () => {
console.log(`Server listening on port ${process.env.PORT || appConfig.PORT || 8080} successfully`);
LOG.info(`Server listening on port ${process.env.PORT || appConfig.PORT || 8080} successfully`);
});
63 changes: 63 additions & 0 deletions skeletons/src/logger/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

import path from 'path';
import fs from 'fs';
import { appConfig } from '@config/app.config';

/**
* @author sivabharathy
*
* @param {*} dirname
* @returns
*/
const mkdirsSync = function(dirname) {
if (fs.existsSync(dirname)) {
return true;
}
if (mkdirsSync(path.dirname(dirname))) {
fs.mkdirSync(dirname);
return true;
}
}
mkdirsSync(appConfig.LOG_DIRECTORY);

const errorLog = require('nila-logger').createSimpleLogger({
logFilePath: appConfig.LOG_DIRECTORY+'/error.log',
timestampFormat: 'YYYY-MM-DD HH:mm:ss'
});

const accessLog = require('nila-logger').createSimpleLogger({
logFilePath: appConfig.LOG_DIRECTORY+'/access.log',
timestampFormat: 'YYYY-MM-DD HH:mm:ss'
});


/**
* @author sivabharathy
*
* @class Logger
*/
class Logger {

error(errorMessage) {
errorLog.error(errorMessage);
}

debug(message) {
accessLog.debug(message);
}

warn(message) {
accessLog.warn(message);
}

info(message) {
accessLog.info(message);
}

}


export const LOG = new Logger();



0 comments on commit 61322b8

Please sign in to comment.