Skip to content

Commit

Permalink
Merge pull request #1 from marcelooblan2016/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
marcelooblan2016 authored Oct 26, 2022
2 parents 707d916 + 6588f55 commit 2737b09
Show file tree
Hide file tree
Showing 12 changed files with 538 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
test/*.log
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# MrxPlogger
Nodejs storage log
# Installation
```bash
npm i mrx-plogger
```
## Usage
```bash
const {plogger} = require('mrx-plogger');
( async () => {
// create a logfile within the same folder
let ploggerIniatiated = new plogger({logFileName: 'test.log'});
ploggerIniatiated.log("test hello0");
ploggerIniatiated.info("test hello1");
ploggerIniatiated.warning("test hello2");
ploggerIniatiated.error("test hello3");
})()
```
## Output
```bash
[2022-10-26 10:06:39PM] INFO: test hello0
[2022-10-26 10:06:39PM] INFO: test hello1
[2022-10-26 10:06:39PM] WARNING: test hello2
[2022-10-26 10:06:39PM] ERROR: test hello3

```
68 changes: 68 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.plogger = void 0;
const fs = __importStar(require("fs-extra"));
const moment_1 = __importDefault(require("moment"));
class plogger {
constructor(options) {
var _a;
this.logFileName = options.logFileName;
this.dateFormat = (_a = options.dateFormat) !== null && _a !== void 0 ? _a : `YYYY-MM-DD hh:mm:ssA`;
}
/**
* Write message to the log file with details
* Sample: [2022-10-05 11:03:44] local.INFO: YV4A22RL4M1768603
* @param string message
* @param string prefix
* @return boolean
*/
log(message, prefix = 'INFO') {
try {
let content = [
`[${(0, moment_1.default)().format(this.dateFormat)}]`,
`${prefix}:`,
typeof message == 'object' ? JSON.stringify(message) : message,
].join(" ");
fs.appendFileSync(this.logFileName, `${content}\n`);
return true;
}
catch (error) { }
return false;
}
/**
* Shortcuts for: info, error, warning
* @param string message
* @param string prefix
* @return boolean
**/
info(message, prefix = 'INFO') { return this.log(message, prefix); }
error(message, prefix = 'ERROR') { return this.log(message, prefix); }
warning(message, prefix = 'WARNING') { return this.log(message, prefix); }
}
exports.plogger = plogger;
35 changes: 0 additions & 35 deletions index.js

This file was deleted.

Loading

0 comments on commit 2737b09

Please sign in to comment.