-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from marcelooblan2016/develop
Develop
- Loading branch information
Showing
12 changed files
with
538 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
node_modules/ | ||
test/*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.