@restroom-mw/logger
Advanced tools
Comparing version 0.13.1-1a00f53.85 to 0.13.1-210e8cc.116
@@ -1,4 +0,26 @@ | ||
export declare const APPEND = "append the string {} to the logfile in {}"; | ||
export declare const APPEND_NAMED = "append the string {} to the logfile named by {}"; | ||
export declare const APPEND_ARRAY = "append the array of strings {} to the logfile named by {}"; | ||
export declare enum Action { | ||
/** | ||
* `Then I append the string 'log' to the logfile in 'logPath'`<br><br> | ||
* Append the string *log* to the logfile in the *logPath* under the *LOGGER_DIR* directory | ||
* @param {string} log - The name of the variable that contains the log string | ||
* or the log string itself | ||
* @param {string} logPath - Path to the log file | ||
*/ | ||
APPEND = "append the string {} to the logfile in {}", | ||
/** | ||
* `Then I append the string 'log' to the logfile named by 'logName'`<br><br> | ||
* Append the string *log* to the logfile in the variable *logName* under the *LOGGER_DIR* directory | ||
* @param {string} log - The name of the variable that contains the log string | ||
* or the log string itself | ||
* @param {string} logName - Name of the variable the contains the path to log file | ||
*/ | ||
APPEND_NAMED = "append the string {} to the logfile named by {}", | ||
/** | ||
* `Then I append the array of strings 'logArray' to the logfile named by 'logName'`<br><br> | ||
* Append the array of strings *logArray* to the logfile in the variable *logName* under the *LOGGER_DIR* directory | ||
* @param {string} logArray - The name of the variable that contains the array of log strings | ||
* @param {string} logName - Name of the variable the contains the path to log file | ||
*/ | ||
APPEND_ARRAY = "append the array of strings {} to the logfile named by {}" | ||
} | ||
//# sourceMappingURL=actions.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.APPEND_ARRAY = exports.APPEND_NAMED = exports.APPEND = void 0; | ||
exports.APPEND = "append the string {} to the logfile in {}"; | ||
exports.APPEND_NAMED = "append the string {} to the logfile named by {}"; | ||
exports.APPEND_ARRAY = "append the array of strings {} to the logfile named by {}"; | ||
exports.Action = void 0; | ||
var Action; | ||
(function (Action) { | ||
/** | ||
* `Then I append the string 'log' to the logfile in 'logPath'`<br><br> | ||
* Append the string *log* to the logfile in the *logPath* under the *LOGGER_DIR* directory | ||
* @param {string} log - The name of the variable that contains the log string | ||
* or the log string itself | ||
* @param {string} logPath - Path to the log file | ||
*/ | ||
Action["APPEND"] = "append the string {} to the logfile in {}"; | ||
/** | ||
* `Then I append the string 'log' to the logfile named by 'logName'`<br><br> | ||
* Append the string *log* to the logfile in the variable *logName* under the *LOGGER_DIR* directory | ||
* @param {string} log - The name of the variable that contains the log string | ||
* or the log string itself | ||
* @param {string} logName - Name of the variable the contains the path to log file | ||
*/ | ||
Action["APPEND_NAMED"] = "append the string {} to the logfile named by {}"; | ||
/** | ||
* `Then I append the array of strings 'logArray' to the logfile named by 'logName'`<br><br> | ||
* Append the array of strings *logArray* to the logfile in the variable *logName* under the *LOGGER_DIR* directory | ||
* @param {string} logArray - The name of the variable that contains the array of log strings | ||
* @param {string} logName - Name of the variable the contains the path to log file | ||
*/ | ||
Action["APPEND_ARRAY"] = "append the array of strings {} to the logfile named by {}"; | ||
})(Action = exports.Action || (exports.Action = {})); |
@@ -20,4 +20,4 @@ "use strict"; | ||
const utils_1 = require("@restroom-mw/utils"); | ||
const actions_1 = require("./actions"); | ||
require("dotenv").config(); | ||
const actions_1 = require("./actions"); | ||
exports.LOGGER_DIR = process.env.LOGGER_DIR; | ||
@@ -34,3 +34,3 @@ const validatePath = (0, utils_1.validateSubdir)(exports.LOGGER_DIR); | ||
const { result, zencode } = params; | ||
const addLog = (sentences, where) => { | ||
const addLog = (sentences, where) => __awaiter(void 0, void 0, void 0, function* () { | ||
const absolutePath = path_1.default.resolve(path_1.default.join(exports.LOGGER_DIR, where)); | ||
@@ -43,11 +43,14 @@ validatePath(absolutePath); | ||
sentences.forEach((v) => ws.write(`${v}\n`)); | ||
}; | ||
if (zencode.match(actions_1.APPEND)) { | ||
const params = zencode.chunkedParamsOf(actions_1.APPEND, 2); | ||
yield new Promise((resolve, reject) => { | ||
ws.close(() => resolve()); | ||
}); | ||
}); | ||
if (zencode.match(actions_1.Action.APPEND)) { | ||
const params = zencode.chunkedParamsOf(actions_1.Action.APPEND, 2); | ||
for (const [sentence, where] of params) { | ||
addLog([result[sentence] || input[sentence] || sentence], where); | ||
yield addLog([result[sentence] || input[sentence] || sentence], where); | ||
} | ||
} | ||
if (zencode.match(actions_1.APPEND_NAMED)) { | ||
const params = zencode.chunkedParamsOf(actions_1.APPEND_NAMED, 2); | ||
if (zencode.match(actions_1.Action.APPEND_NAMED)) { | ||
const params = zencode.chunkedParamsOf(actions_1.Action.APPEND_NAMED, 2); | ||
for (const [sentence, pathName] of params) { | ||
@@ -58,7 +61,7 @@ const logPath = result[pathName] || input[pathName]; | ||
} | ||
addLog([result[sentence] || input[sentence] || sentence], logPath); | ||
yield addLog([result[sentence] || input[sentence] || sentence], logPath); | ||
} | ||
} | ||
if (zencode.match(actions_1.APPEND_ARRAY)) { | ||
const params = zencode.chunkedParamsOf(actions_1.APPEND_ARRAY, 2); | ||
if (zencode.match(actions_1.Action.APPEND_ARRAY)) { | ||
const params = zencode.chunkedParamsOf(actions_1.Action.APPEND_ARRAY, 2); | ||
for (const [arrayName, where] of params) { | ||
@@ -69,3 +72,3 @@ const sentences = input[arrayName] || result[arrayName]; | ||
} | ||
addLog(sentences, result[where] || input[where] || where); | ||
yield addLog(sentences, result[where] || input[where] || where); | ||
} | ||
@@ -72,0 +75,0 @@ } |
{ | ||
"name": "@restroom-mw/logger", | ||
"version": "0.13.1-1a00f53.85+1a00f53", | ||
"version": "0.13.1-210e8cc.116+210e8cc", | ||
"description": "Utilities middleware to work with files for Restroom", | ||
@@ -23,3 +23,3 @@ "author": "Alberto Lerda <alberto@dyne.org>", | ||
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo", | ||
"doc": "documentation readme src/** -g -f md -s 'API' --readme-file ../../docs/packages/redis.md --shallow", | ||
"doc": "documentation readme src/** -g -f md -s 'API' --readme-file ../../docs/packages/logger.md --shallow", | ||
"links": "yarn link", | ||
@@ -37,3 +37,3 @@ "unlinks": "yarn unlink", | ||
}, | ||
"gitHead": "1a00f535babfac139a9d585879dee42eeb4d1eac" | ||
"gitHead": "210e8cc0e37e723e69d42f7bd968fb7d2d317034" | ||
} |
@@ -1,3 +0,25 @@ | ||
export const APPEND = "append the string {} to the logfile in {}"; | ||
export const APPEND_NAMED = "append the string {} to the logfile named by {}"; | ||
export const APPEND_ARRAY = "append the array of strings {} to the logfile named by {}"; | ||
export enum Action { | ||
/** | ||
* `Then I append the string 'log' to the logfile in 'logPath'`<br><br> | ||
* Append the string *log* to the logfile in the *logPath* under the *LOGGER_DIR* directory | ||
* @param {string} log - The name of the variable that contains the log string | ||
* or the log string itself | ||
* @param {string} logPath - Path to the log file | ||
*/ | ||
APPEND = "append the string {} to the logfile in {}", | ||
/** | ||
* `Then I append the string 'log' to the logfile named by 'logName'`<br><br> | ||
* Append the string *log* to the logfile in the variable *logName* under the *LOGGER_DIR* directory | ||
* @param {string} log - The name of the variable that contains the log string | ||
* or the log string itself | ||
* @param {string} logName - Name of the variable the contains the path to log file | ||
*/ | ||
APPEND_NAMED = "append the string {} to the logfile named by {}", | ||
/** | ||
* `Then I append the array of strings 'logArray' to the logfile named by 'logName'`<br><br> | ||
* Append the array of strings *logArray* to the logfile in the variable *logName* under the *LOGGER_DIR* directory | ||
* @param {string} logArray - The name of the variable that contains the array of log strings | ||
* @param {string} logName - Name of the variable the contains the path to log file | ||
*/ | ||
APPEND_ARRAY = "append the array of strings {} to the logfile named by {}" | ||
} |
@@ -7,5 +7,6 @@ import {Restroom} from "@restroom-mw/core"; | ||
import {validateSubdir} from "@restroom-mw/utils"; | ||
import { Action } from "./actions" | ||
require("dotenv").config(); | ||
import {APPEND, APPEND_NAMED, APPEND_ARRAY} from "./actions"; | ||
export const LOGGER_DIR = process.env.LOGGER_DIR; | ||
@@ -28,3 +29,3 @@ | ||
const addLog = (sentences: string[], where: string) => { | ||
const addLog = async (sentences: string[], where: string) => { | ||
const absolutePath = path.resolve(path.join(LOGGER_DIR, where)); | ||
@@ -38,12 +39,15 @@ validatePath(absolutePath); | ||
sentences.forEach( (v) => ws.write(`${v}\n`) ) | ||
await new Promise<void>((resolve, reject) => { | ||
ws.close(() => resolve()) | ||
}) | ||
} | ||
if (zencode.match(APPEND)) { | ||
const params = zencode.chunkedParamsOf(APPEND, 2); | ||
if (zencode.match(Action.APPEND)) { | ||
const params = zencode.chunkedParamsOf(Action.APPEND, 2); | ||
for(const [ sentence, where ] of params) { | ||
addLog([ result[sentence] || input[sentence] || sentence ], where); | ||
await addLog([ result[sentence] || input[sentence] || sentence ], where); | ||
} | ||
} | ||
if (zencode.match(APPEND_NAMED)) { | ||
const params = zencode.chunkedParamsOf(APPEND_NAMED, 2); | ||
if (zencode.match(Action.APPEND_NAMED)) { | ||
const params = zencode.chunkedParamsOf(Action.APPEND_NAMED, 2); | ||
for(const [ sentence, pathName ] of params) { | ||
@@ -55,7 +59,7 @@ const logPath = result[pathName] || input[pathName]; | ||
} | ||
addLog([ result[sentence] || input[sentence] || sentence ], logPath); | ||
await addLog([ result[sentence] || input[sentence] || sentence ], logPath); | ||
} | ||
} | ||
if (zencode.match(APPEND_ARRAY)) { | ||
const params = zencode.chunkedParamsOf(APPEND_ARRAY, 2); | ||
if (zencode.match(Action.APPEND_ARRAY)) { | ||
const params = zencode.chunkedParamsOf(Action.APPEND_ARRAY, 2); | ||
for(const [arrayName, where] of params) { | ||
@@ -67,3 +71,3 @@ const sentences = input[arrayName] || result[arrayName]; | ||
} | ||
addLog(sentences, | ||
await addLog(sentences, | ||
result[where] || input[where] || where); | ||
@@ -70,0 +74,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
47056
220