Skip to content

Commit 2737b09

Browse files
Merge pull request #1 from marcelooblan2016/develop
Develop
2 parents 707d916 + 6588f55 commit 2737b09

File tree

12 files changed

+538
-39
lines changed

12 files changed

+538
-39
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
node_modules/
2+
test/*.log

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# MrxPlogger
2+
Nodejs storage log
3+
# Installation
4+
```bash
5+
npm i mrx-plogger
6+
```
7+
## Usage
8+
```bash
9+
const {plogger} = require('mrx-plogger');
10+
( async () => {
11+
// create a logfile within the same folder
12+
let ploggerIniatiated = new plogger({logFileName: 'test.log'});
13+
ploggerIniatiated.log("test hello0");
14+
ploggerIniatiated.info("test hello1");
15+
ploggerIniatiated.warning("test hello2");
16+
ploggerIniatiated.error("test hello3");
17+
})()
18+
```
19+
## Output
20+
```bash
21+
[2022-10-26 10:06:39PM] INFO: test hello0
22+
[2022-10-26 10:06:39PM] INFO: test hello1
23+
[2022-10-26 10:06:39PM] WARNING: test hello2
24+
[2022-10-26 10:06:39PM] ERROR: test hello3
25+
26+
```

dist/index.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
25+
var __importDefault = (this && this.__importDefault) || function (mod) {
26+
return (mod && mod.__esModule) ? mod : { "default": mod };
27+
};
28+
Object.defineProperty(exports, "__esModule", { value: true });
29+
exports.plogger = void 0;
30+
const fs = __importStar(require("fs-extra"));
31+
const moment_1 = __importDefault(require("moment"));
32+
class plogger {
33+
constructor(options) {
34+
var _a;
35+
this.logFileName = options.logFileName;
36+
this.dateFormat = (_a = options.dateFormat) !== null && _a !== void 0 ? _a : `YYYY-MM-DD hh:mm:ssA`;
37+
}
38+
/**
39+
* Write message to the log file with details
40+
* Sample: [2022-10-05 11:03:44] local.INFO: YV4A22RL4M1768603
41+
* @param string message
42+
* @param string prefix
43+
* @return boolean
44+
*/
45+
log(message, prefix = 'INFO') {
46+
try {
47+
let content = [
48+
`[${(0, moment_1.default)().format(this.dateFormat)}]`,
49+
`${prefix}:`,
50+
typeof message == 'object' ? JSON.stringify(message) : message,
51+
].join(" ");
52+
fs.appendFileSync(this.logFileName, `${content}\n`);
53+
return true;
54+
}
55+
catch (error) { }
56+
return false;
57+
}
58+
/**
59+
* Shortcuts for: info, error, warning
60+
* @param string message
61+
* @param string prefix
62+
* @return boolean
63+
**/
64+
info(message, prefix = 'INFO') { return this.log(message, prefix); }
65+
error(message, prefix = 'ERROR') { return this.log(message, prefix); }
66+
warning(message, prefix = 'WARNING') { return this.log(message, prefix); }
67+
}
68+
exports.plogger = plogger;

index.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)