From b455d1d7821a1e7bd1ba55d267ae7045830ad1ca Mon Sep 17 00:00:00 2001 From: Andrey <56131670+and-adad@users.noreply.github.com> Date: Fri, 26 Jul 2024 19:20:13 +0500 Subject: [PATCH 01/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbd55d6..ee6ec40 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Практикум по функциональному программированию ШРИ -Применение приемов функционального программирования, на ральной задаче. +Применение приемов функционального программирования, на реальной задаче. ### Файлы From 3aa6055a0798512a274b9dff256ab3e6d64953bd Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 16:37:28 +0500 Subject: [PATCH 02/22] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D0=BB=D1=81=D1=8F=20=D0=BA=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=D0=BB=D1=83=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0,=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20=D0=B2=D1=81=D0=B5?= =?UTF-8?q?=20=D0=B2=20=D0=B3=D0=BB=D0=B0=D0=B2=D0=BD=D0=BE=D0=BC=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=B5=20=D0=BD=D0=B0=20=D0=B8=D0=BC=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=D1=82=D0=B8=D0=B2=D0=BD=D1=8B=D0=B9=20=D1=81?= =?UTF-8?q?=D1=82=D0=B8=D0=BB=D1=8C=20=D0=97=D0=B0=D0=BE=D0=B4=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=B8=D1=81=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=D0=B2=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D0=BE?= =?UTF-8?q?=D0=BD=20=D0=B2=D1=8B=D0=B4=D0=B0=D0=B2=D0=B0=D0=BB=20=D1=82?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=B2?= =?UTF-8?q?=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D0=B4=D0=B2=D1=83=D1=85=20?= =?UTF-8?q?=D0=BA=D0=B0=D0=BA=20=D0=B2=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- errorsLog.json | 6 +++ logs | 1 + src/index.js | 102 +++++++++++++++++-------------------------------- 3 files changed, 42 insertions(+), 67 deletions(-) diff --git a/errorsLog.json b/errorsLog.json index 0c50a2a..d073301 100644 --- a/errorsLog.json +++ b/errorsLog.json @@ -10,5 +10,11 @@ "type": "ERROR", "component": "search-interfaces-infra", "message": "403 Forbidden CI API" + }, + { + "time": "2023-07-12 22:14:19,813", + "type": "ERROR", + "component": "search-interfaces-infra", + "message": "403 Forbidden CI API " } ] \ No newline at end of file diff --git a/logs b/logs index 968b7d3..a4542e0 100644 --- a/logs +++ b/logs @@ -23,6 +23,7 @@ 2023-07-12 22:14:21,694 (0.005s) INFO (yandex-market) [d08844ba] Running: vim 2023-07-12 22:14:21,701 (0.007s) DEBUG (yandex-market) [d08844ba] PID=2222 OUT=-1 ERR=-1 2023-07-12 22:14:19,813 (0.000s) ERROR (search-interfaces-infra) 403 Forbidden CI API +2023-07-12 22:14:19,813 (0.000s) ERROR (search-interfaces-infra) 403 Forbidden CI API 2023-07-12 22:14:19,813 (0.000s) INFO (test) Switched to subsystem The standard chunk of Lorem Ipsum used since the 1500s. 2023-07-12 22:14:19,813 (0.000s) INFO (test) Switched to subsystem Lorem Ipsum comes from sections 1.10.32 and 1.10.33 2023-07-12 22:14:19,813 (0.000s) INFO (test) generated Lorem Ipsum is therefore always free from repetition diff --git a/src/index.js b/src/index.js index c0202b8..adb98aa 100644 --- a/src/index.js +++ b/src/index.js @@ -1,81 +1,49 @@ -import { - allPass, - anyPass, - applySpec, - compose, - curry, - equals, - filter, - map, - match, - nth, - partial, - partialRight, - prop, - tap, - tryCatch, -} from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); -const curriedLog = curry(log); -const logRed = curriedLog('red'); -const logGreen = curriedLog('green'); -const logError = logRed('Error'); -const logReadFile = logGreen('Read file'); -const logWriteFile = logGreen('Write file'); +const path = process.env.FILE_PATH; -const formatLogs = partialRight(JSON.stringify, [null, 2]); -const writeErrorLogs = partial(writeFile, ['errorsLog.json', '../']); +log('green', 'Read file', path); -const getMessage = prop('message'); -const getType = prop('type'); -const getComponent = prop('component'); -const getParsedLogTime = nth(1); -const getParsedLogType = nth(2); -const getParsedLogComponent = nth(3); -const getParsedLogMassage = nth(4); +let fileData; -const logErrorMessage = compose(logError, getMessage); +try { + fileData = readFile(path); +} catch (e) { + log('red', 'Error', e.message); +} -const isError = equals('ERROR'); -const isWarn = equals('WARN'); -const isInfraComponent = equals('search-interfaces-infra'); -const isErrorLog = compose(isError, getType); -const isWarnLog = compose(isWarn, getType); -const isInfraComponentLog = compose(isInfraComponent, getComponent); +const logs = fileData.match(/[^\r\n]+/g); -const isErrorOrWarnLog = anyPass([isErrorLog, isWarnLog]); -const isInfraErrorLog = allPass([isErrorOrWarnLog, isInfraComponentLog]); +const logsWithErrors = []; -const splitFileByLine = match(/[^\r\n]+/g); -const parseLog = match(/([\d-:,\s]+)\s\(.+\)\s(\w+)\s+\(([^)]+)\)\s(.+)/); -const getParsedLogInfo = applySpec({ - time: getParsedLogTime, - type: getParsedLogType, - component: getParsedLogComponent, - message: getParsedLogMassage, -}); +for (let i = 0; i < logs.length; i++) { + const logData = logs[i].match( + /([\d-:,\s]+)\s\(.+\)\s(\w+)\s+\(([^)]+)\)\s(.+)/, + ); -const createSafeFunction = (fn) => tryCatch(fn, logErrorMessage); -const readFileSafe = createSafeFunction(readFile); -const writeErrorLogsSafe = createSafeFunction(writeErrorLogs); + const logInfo = { + time: logData[1], + type: logData[2], + component: logData[3], + message: logData[4], + }; -const getInfraErrorsLog = compose( - filter(isInfraErrorLog), - map(getParsedLogInfo), - map(parseLog), -); + if ( + (logInfo.type === 'ERROR' || logInfo.type === 'WARN') && + logInfo.component === 'search-interfaces-infra' + ) { + logsWithErrors.push(logInfo); + } +} -const app = compose( - writeErrorLogsSafe, - tap(logWriteFile), - formatLogs, - getInfraErrorsLog, - splitFileByLine, - readFileSafe, - tap(logReadFile), -); +const formatedLogs = JSON.stringify(logsWithErrors, null, 2); -app(process.env.FILE_PATH); +log('green', 'Write to file', formatedLogs); + +try { + writeFile('errorsLog.json', '../', formatedLogs); +} catch (e) { + log('red', 'Error', e.message); +} From f59ef5f892890bd7cf5757e2aaca6ba591c0c81f Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 17:34:36 +0500 Subject: [PATCH 03/22] =?UTF-8?q?=D1=83=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=20=D0=B2=D0=B8=D0=B4=D0=B5=D0=BE=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B4=D0=BE=D0=BB=D0=B6?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D1=83=20=D0=BC=D0=B5=D0=BD=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BB=D0=BE=D0=BC=D0=B0=D0=BB=D0=BE=D1=81=D1=8C=20curry=20is?= =?UTF-8?q?=20not=20defined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index adb98aa..ed14536 100644 --- a/src/index.js +++ b/src/index.js @@ -2,9 +2,11 @@ import { log, readFile, writeFile } from './helpers/index'; console.clear(); +const curriedLog = curry(log); + const path = process.env.FILE_PATH; -log('green', 'Read file', path); +curriedLog('green')('Read file', path); let fileData; From b46302dc947f4ac3c171af1ffc189dfe6d04b921 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 17:56:45 +0500 Subject: [PATCH 04/22] =?UTF-8?q?=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D0=B0=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index ed14536..437dff7 100644 --- a/src/index.js +++ b/src/index.js @@ -3,10 +3,11 @@ import { log, readFile, writeFile } from './helpers/index'; console.clear(); const curriedLog = curry(log); +const logGreen = curriedLog('green'); const path = process.env.FILE_PATH; -curriedLog('green')('Read file', path); +logGreen('Read file', path); let fileData; From f5c30c8bfd4d9731be10af52b717f8ca13d8f77a Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 18:04:43 +0500 Subject: [PATCH 05/22] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20curry=20=D0=B8=20=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B6=D0=BD=D0=B5=D0=BC=D1=83=20=D0=B2=D1=81=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D1=82=D0=B0=D0=BC?= =?UTF-8?q?=20=D1=83=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B0=20=D0=B2=D0=B8?= =?UTF-8?q?=D0=B4=D0=B5=D0=BE=20=D0=BC=D0=B0=D0=B3=D0=B8=D1=87=D0=B5=D1=81?= =?UTF-8?q?=D0=BA=D0=B8=D0=BC=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B7=D0=BE=D0=BC?= =?UTF-8?q?=20=D1=81=D1=82=D1=80=D0=BE=D1=87=D0=BA=D0=B0=20=D1=81=20=D0=B8?= =?UTF-8?q?=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D0=B0=D0=BC=D0=B8=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=8F=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index ed14536..8f0f560 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +import { curry } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); From d46bbef693a048c7804b16992038ce79c2c3a761 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 18:15:42 +0500 Subject: [PATCH 06/22] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B8=D0=B7=D0=B2?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=20=D0=BD=D0=B5=D0=BA=D0=B8=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC=D1=83?= =?UTF-8?q?=20=D0=B2=D1=81=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index b6aedf2..180b827 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ const logGreen = curriedLog('green'); const path = process.env.FILE_PATH; logGreen('Read file', path); - +// поменял на logGreen let fileData; try { From 8f2eec748affcbf6522ab6d610abfabea24a88a5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 18:37:06 +0500 Subject: [PATCH 07/22] =?UTF-8?q?=D1=82=D0=BE=20=D0=B6=D0=B5=20=D1=81?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B5=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=B5?= =?UTF-8?q?=D0=BC=20=D1=81=20=D0=BA=D1=80=D0=B0=D1=81=D0=BD=D1=8B=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 180b827..56cf3c0 100644 --- a/src/index.js +++ b/src/index.js @@ -5,17 +5,18 @@ console.clear(); const curriedLog = curry(log); const logGreen = curriedLog('green'); +const logRed = curriedLog('red'); const path = process.env.FILE_PATH; logGreen('Read file', path); -// поменял на logGreen + let fileData; try { fileData = readFile(path); } catch (e) { - log('red', 'Error', e.message); + logRed('Error', e.message); } const logs = fileData.match(/[^\r\n]+/g); @@ -44,10 +45,10 @@ for (let i = 0; i < logs.length; i++) { const formatedLogs = JSON.stringify(logsWithErrors, null, 2); -log('green', 'Write to file', formatedLogs); +logGreen('Write to file', formatedLogs); try { writeFile('errorsLog.json', '../', formatedLogs); } catch (e) { - log('red', 'Error', e.message); + logRed('Error', e.message); } From f4b62319ee89b5dc9bc519bc6905f06367a821ab Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 19:18:45 +0500 Subject: [PATCH 08/22] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=B2=D1=81?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=D0=B6=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 56cf3c0..f808b46 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { curry } from 'ramda'; +import { curry, prop } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -7,16 +7,22 @@ const curriedLog = curry(log); const logGreen = curriedLog('green'); const logRed = curriedLog('red'); +const logError = logRed('Error'); +const logReadFile = logGreen('Read file'); +const logWriteFile = logGreen('Write file'); + +const getMessage = prop('message'); + const path = process.env.FILE_PATH; -logGreen('Read file', path); +logReadFile(path); let fileData; try { fileData = readFile(path); } catch (e) { - logRed('Error', e.message); + logError(getMessage(e)); } const logs = fileData.match(/[^\r\n]+/g); @@ -45,10 +51,10 @@ for (let i = 0; i < logs.length; i++) { const formatedLogs = JSON.stringify(logsWithErrors, null, 2); -logGreen('Write to file', formatedLogs); +logWriteFile(formatedLogs); try { writeFile('errorsLog.json', '../', formatedLogs); } catch (e) { - logRed('Error', e.message); + logError(e.message); } From 129b8163e29b0df45b45ddde3087315fd6428bd3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 19:28:51 +0500 Subject: [PATCH 09/22] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=B2=D1=81?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=D0=B6=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index f808b46..7aeef53 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { curry, prop } from 'ramda'; +import { compose, curry, prop } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -13,6 +13,9 @@ const logWriteFile = logGreen('Write file'); const getMessage = prop('message'); +const logErrorMessage = compose(logError, getMessage); +// именно в порядке сначала getMessage потом logError у compose оно идет в порядке наоборот + const path = process.env.FILE_PATH; logReadFile(path); @@ -22,7 +25,7 @@ let fileData; try { fileData = readFile(path); } catch (e) { - logError(getMessage(e)); + logErrorMessage(e); } const logs = fileData.match(/[^\r\n]+/g); @@ -56,5 +59,5 @@ logWriteFile(formatedLogs); try { writeFile('errorsLog.json', '../', formatedLogs); } catch (e) { - logError(e.message); + logErrorMessage(e); } From e013ba90f96ea0af21fa12a0fd920168194d003a Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 21:08:51 +0500 Subject: [PATCH 10/22] =?UTF-8?q?=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B2=D1=83=D1=8E=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D1=83=D0=BB=D1=8F=D1=80=D0=BA=D1=83=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D1=81=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BD=D1=8F=D1=82=D0=BD=D1=8B=D0=BC=20=D0=BD=D0=B0=D0=B7?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 7aeef53..7f41fc5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop } from 'ramda'; +import { compose, curry, prop, match } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -13,8 +13,9 @@ const logWriteFile = logGreen('Write file'); const getMessage = prop('message'); +const splitFileByLine = match(/[^\r\n]+/g); + const logErrorMessage = compose(logError, getMessage); -// именно в порядке сначала getMessage потом logError у compose оно идет в порядке наоборот const path = process.env.FILE_PATH; @@ -28,7 +29,7 @@ try { logErrorMessage(e); } -const logs = fileData.match(/[^\r\n]+/g); +const logs = splitFileByLine(fileData); const logsWithErrors = []; From d89f33d761af34443355ee9374fba8404d3b5bc3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Jul 2024 21:15:57 +0500 Subject: [PATCH 11/22] =?UTF-8?q?=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D1=82=D0=BE=D1=80=D1=83=D1=8E=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D1=83=D0=BB=D1=8F=D1=80=D0=BA=D1=83=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D1=81=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BD=D1=8F=D1=82=D0=BD=D1=8B=D0=BC=20=D0=BD=D0=B0=D0=B7?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 7f41fc5..646b00d 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,7 @@ const getMessage = prop('message'); const splitFileByLine = match(/[^\r\n]+/g); const logErrorMessage = compose(logError, getMessage); +const parseLog = match(/([\d-:,\s]+)\s\(.+\)\s(\w+)\s+\(([^)]+)\)\s(.+)/); const path = process.env.FILE_PATH; @@ -34,9 +35,7 @@ const logs = splitFileByLine(fileData); const logsWithErrors = []; for (let i = 0; i < logs.length; i++) { - const logData = logs[i].match( - /([\d-:,\s]+)\s\(.+\)\s(\w+)\s+\(([^)]+)\)\s(.+)/, - ); + const logData = parseLog(logs[i]); const logInfo = { time: logData[1], From 0325c1cc3fafa5c0c9976018cd7c983facf024e4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 11:22:50 +0500 Subject: [PATCH 12/22] =?UTF-8?q?=D0=BC=D1=8B=20=D0=BD=D0=B0=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BB=D0=B8=20=D1=82=D1=80=D0=B8=20=D1=84=D1=83?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D0=BF=D1=80=D0=B5=D0=B4=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=D1=82=D0=B0=20=D0=B8=20=D0=B4=D0=B2=D0=B5=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D0=B3=D0=B5=D1=82=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D1=8B=20=D0=B8=20=D0=B2=D1=81=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC=D1=83=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 646b00d..db3999a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match } from 'ramda'; +import { compose, curry, prop, match, equals } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -12,12 +12,21 @@ const logReadFile = logGreen('Read file'); const logWriteFile = logGreen('Write file'); const getMessage = prop('message'); +const getType = prop('type'); +const getComponent = prop('component'); const splitFileByLine = match(/[^\r\n]+/g); const logErrorMessage = compose(logError, getMessage); const parseLog = match(/([\d-:,\s]+)\s\(.+\)\s(\w+)\s+\(([^)]+)\)\s(.+)/); +const isError = equals('ERROR'); +const isWarn = equals('WARN'); +const isInfraComponent = equals('search-interfaces-infra'); +const isErrorLog = compose(isError, getType); +const isWarnLog = compose(isWarn, getType); +const isInfraComponentLog = compose(isInfraComponent, getComponent); + const path = process.env.FILE_PATH; logReadFile(path); @@ -45,8 +54,8 @@ for (let i = 0; i < logs.length; i++) { }; if ( - (logInfo.type === 'ERROR' || logInfo.type === 'WARN') && - logInfo.component === 'search-interfaces-infra' + (isErrorLog(logInfo) || isWarnLog(logInfo)) && + isInfraComponentLog(logInfo) ) { logsWithErrors.push(logInfo); } From 564d5fb40759205d4fee1d1e34210af21cfa7360 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 11:43:25 +0500 Subject: [PATCH 13/22] =?UTF-8?q?=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BD=D0=B0=20allPass=20anyPass=20=D0=B1=D0=BB=D0=BE?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=B2=20=D0=BA=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D1=8B=D1=85=20=D1=88=D0=BB=D0=BE=20=D1=81?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5=20=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B5=D0=B6?= =?UTF-8?q?=D0=BD=D0=B5=D0=BC=D1=83=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index db3999a..491b789 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match, equals } from 'ramda'; +import { compose, curry, prop, match, equals, anyPass, allPass } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -27,6 +27,9 @@ const isErrorLog = compose(isError, getType); const isWarnLog = compose(isWarn, getType); const isInfraComponentLog = compose(isInfraComponent, getComponent); +const isErrorOrWarnLog = anyPass([isWarnLog, isErrorLog]); +const isInfraErrorLog = allPass([isErrorOrWarnLog, isInfraComponentLog]); + const path = process.env.FILE_PATH; logReadFile(path); @@ -53,10 +56,7 @@ for (let i = 0; i < logs.length; i++) { message: logData[4], }; - if ( - (isErrorLog(logInfo) || isWarnLog(logInfo)) && - isInfraComponentLog(logInfo) - ) { + if (isInfraErrorLog(logInfo)) { logsWithErrors.push(logInfo); } } From 90fd29434b5c2ea08c1508f1fb34b48dd6292672 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 12:27:12 +0500 Subject: [PATCH 14/22] =?UTF-8?q?time=20type=20component=20message=20?= =?UTF-8?q?=D0=B2=20=D1=84=D1=83=D0=BA=D1=86=D0=B8=D0=B8=20=D0=B3=D0=B5?= =?UTF-8?q?=D1=82=D1=82=D0=B5=D1=80=D1=8B,=20=D0=BA=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D1=8B=D0=B5=20=D0=B1=D1=83=D0=B4=D1=83=D1=82=20=D1=8D?= =?UTF-8?q?=D1=82=D0=BE=20=D0=B2=20=D1=81=D0=B5=D0=B1=D0=B5=20=D0=B8=D0=BD?= =?UTF-8?q?=D0=BA=D0=B0=D0=BF=D1=81=D1=83=D0=BB=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 491b789..2c2c54d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match, equals, anyPass, allPass } from 'ramda'; +import { compose, curry, prop, match, equals, anyPass, allPass, nth } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -15,6 +15,11 @@ const getMessage = prop('message'); const getType = prop('type'); const getComponent = prop('component'); +const getParsedLogTime = nth(1); +const getParsedLogType = nth(2); +const getParsedLogComponent = nth(3); +const getParsedLogMessage = nth(4); + const splitFileByLine = match(/[^\r\n]+/g); const logErrorMessage = compose(logError, getMessage); @@ -50,10 +55,10 @@ for (let i = 0; i < logs.length; i++) { const logData = parseLog(logs[i]); const logInfo = { - time: logData[1], - type: logData[2], - component: logData[3], - message: logData[4], + time: getParsedLogTime(logData), + type: getParsedLogType(logData), + component: getParsedLogComponent(logData), + message: getParsedLogMessage(logData), }; if (isInfraErrorLog(logInfo)) { From 2df224557b71c09dab06d1c0dcccebb5da698f66 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 12:39:55 +0500 Subject: [PATCH 15/22] =?UTF-8?q?applySpec=20=D0=B8=20=D0=B2=D1=81=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC?= =?UTF-8?q?=D1=83=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 2c2c54d..6427366 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match, equals, anyPass, allPass, nth } from 'ramda'; +import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -35,6 +35,13 @@ const isInfraComponentLog = compose(isInfraComponent, getComponent); const isErrorOrWarnLog = anyPass([isWarnLog, isErrorLog]); const isInfraErrorLog = allPass([isErrorOrWarnLog, isInfraComponentLog]); +const getLogInfo = applySpec({ + time: getParsedLogTime, + type: getParsedLogType, + component: getParsedLogComponent, + message: getParsedLogMessage, +}); + const path = process.env.FILE_PATH; logReadFile(path); @@ -54,12 +61,7 @@ const logsWithErrors = []; for (let i = 0; i < logs.length; i++) { const logData = parseLog(logs[i]); - const logInfo = { - time: getParsedLogTime(logData), - type: getParsedLogType(logData), - component: getParsedLogComponent(logData), - message: getParsedLogMessage(logData), - }; + const logInfo = getLogInfo(logData); if (isInfraErrorLog(logInfo)) { logsWithErrors.push(logInfo); From 1d10f2ee4bb5e6b794c701c491e870dbb26b1f67 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 13:00:13 +0500 Subject: [PATCH 16/22] =?UTF-8?q?=D0=BE=D0=B1=D1=8A=D0=B5=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B8=D0=BC=20=D0=B2=20=D0=BE=D0=B4=D0=BD=D1=83=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D1=81=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=B7=D0=B8=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B8=20=D0=B2=D1=81=D0=B5=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC=D1=83=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/index.js b/src/index.js index 6427366..b6a9d90 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec } from 'ramda'; +import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -42,6 +42,12 @@ const getLogInfo = applySpec({ message: getParsedLogMessage, }); +const getInfraErrorsLog = compose( + filter(isInfraErrorLog), + map(getLogInfo), + map(parseLog), +); + const path = process.env.FILE_PATH; logReadFile(path); @@ -56,17 +62,7 @@ try { const logs = splitFileByLine(fileData); -const logsWithErrors = []; - -for (let i = 0; i < logs.length; i++) { - const logData = parseLog(logs[i]); - - const logInfo = getLogInfo(logData); - - if (isInfraErrorLog(logInfo)) { - logsWithErrors.push(logInfo); - } -} +const logsWithErrors = getInfraErrorsLog(logs); const formatedLogs = JSON.stringify(logsWithErrors, null, 2); From e019ffd9164ecc36b3300a141b0ed4e7a3e3bd93 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 14:05:49 +0500 Subject: [PATCH 17/22] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D0=BC=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=B2=D1=81=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC=D1=83=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index b6a9d90..2fb59e5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map } from 'ramda'; +import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map, partial } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -68,8 +68,10 @@ const formatedLogs = JSON.stringify(logsWithErrors, null, 2); logWriteFile(formatedLogs); +const writeErrorLogs = partial(writeFile,['errorsLog.json', '../']); + try { - writeFile('errorsLog.json', '../', formatedLogs); + writeErrorLogs(formatedLogs); } catch (e) { logErrorMessage(e); } From cc8efb8c0cf4c70a9c31d4e366572d8bc36d269b Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 14:14:05 +0500 Subject: [PATCH 18/22] =?UTF-8?q?=20=D0=B8=20=D0=B2=D1=81=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC=D1=83=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 2fb59e5..9dabda7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map, partial } from 'ramda'; +import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map, partial, partialRight } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -64,7 +64,9 @@ const logs = splitFileByLine(fileData); const logsWithErrors = getInfraErrorsLog(logs); -const formatedLogs = JSON.stringify(logsWithErrors, null, 2); +const formatLogs = partialRight(JSON.stringify, [null, 2]); + +const formatedLogs = formatLogs(logsWithErrors); logWriteFile(formatedLogs); From f97ef1aa641a34e7d4ad762dbd5207aba766adf9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 14:20:50 +0500 Subject: [PATCH 19/22] =?UTF-8?q?formatLogs=20=D0=B8=20writeErrorLogs=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=20=D0=BF=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=D1=88=D0=B5=20=D0=B2=D1=81=D0=B5=20=D0=BF=D0=BE=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC=D1=83=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 9dabda7..1cebf53 100644 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,9 @@ import { log, readFile, writeFile } from './helpers/index'; console.clear(); +const formatLogs = partialRight(JSON.stringify, [null, 2]); +const writeErrorLogs = partial(writeFile,['errorsLog.json', '../']); + const curriedLog = curry(log); const logGreen = curriedLog('green'); const logRed = curriedLog('red'); @@ -64,14 +67,10 @@ const logs = splitFileByLine(fileData); const logsWithErrors = getInfraErrorsLog(logs); -const formatLogs = partialRight(JSON.stringify, [null, 2]); - const formatedLogs = formatLogs(logsWithErrors); logWriteFile(formatedLogs); -const writeErrorLogs = partial(writeFile,['errorsLog.json', '../']); - try { writeErrorLogs(formatedLogs); } catch (e) { From 1309eec5161d78602b272be4aa8c437d5ae5515f Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 14:40:58 +0500 Subject: [PATCH 20/22] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D1=8F=D1=8E=D1=89=D0=B8=D0=B9?= =?UTF-8?q?=D1=81=D1=8F=20try=20catch=20=D0=BD=D0=B0=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=B2=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=B2=D1=8B=D1=81=D1=88=D0=B5=D0=B3=D0=BE=20=D0=BF=D0=BE=D1=80?= =?UTF-8?q?=D1=8F=D0=B4=D0=BA=D0=B0=20=D0=B2=D1=81=D0=B5=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC=D1=83=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/index.js b/src/index.js index 1cebf53..1ad8fb1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map, partial, partialRight } from 'ramda'; +import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map, partial, partialRight, tryCatch } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -51,17 +51,15 @@ const getInfraErrorsLog = compose( map(parseLog), ); +const createSafeFunction = (fn) => tryCatch(fn, logErrorMessage); +const readFileSafe = createSafeFunction(readFile); +const writeErrorLogsSafe = createSafeFunction(writeErrorLogs); + const path = process.env.FILE_PATH; logReadFile(path); -let fileData; - -try { - fileData = readFile(path); -} catch (e) { - logErrorMessage(e); -} +const fileData = readFileSafe(path); const logs = splitFileByLine(fileData); @@ -71,8 +69,4 @@ const formatedLogs = formatLogs(logsWithErrors); logWriteFile(formatedLogs); -try { - writeErrorLogs(formatedLogs); -} catch (e) { - logErrorMessage(e); -} +writeErrorLogsSafe(formatedLogs); From 7f7db163be6925fddc54d78ad92c8ad4838b8aab Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 21:26:05 +0500 Subject: [PATCH 21/22] =?UTF-8?q?=D0=BE=D0=B1=D1=8A=D0=B5=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B8=D0=BC=20=D0=B2=20=D0=BE=D0=B4=D0=BD=D1=83=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D0=B2=D1=81=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B5=D0=B6=D0=BD=D0=B5=D0=BC=D1=83?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/index.js b/src/index.js index 1ad8fb1..acef2e2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map, partial, partialRight, tryCatch } from 'ramda'; +import { compose, curry, prop, match, equals, anyPass, allPass, nth, applySpec, filter, map, partial, partialRight, tryCatch, tap } from 'ramda'; import { log, readFile, writeFile } from './helpers/index'; console.clear(); @@ -55,18 +55,15 @@ const createSafeFunction = (fn) => tryCatch(fn, logErrorMessage); const readFileSafe = createSafeFunction(readFile); const writeErrorLogsSafe = createSafeFunction(writeErrorLogs); -const path = process.env.FILE_PATH; - -logReadFile(path); - -const fileData = readFileSafe(path); - -const logs = splitFileByLine(fileData); - -const logsWithErrors = getInfraErrorsLog(logs); - -const formatedLogs = formatLogs(logsWithErrors); - -logWriteFile(formatedLogs); +const app = compose( + writeErrorLogsSafe, + tap(logWriteFile), + formatLogs, + getInfraErrorsLog, + splitFileByLine, + readFileSafe, + tap(logReadFile), +); +// в данном случае у нас здесь отсутствует логирование ошибок п.ч. оно ведет себя как процедура а не как функция т.е. она принимает в себя данные но ничего не возвращает поэтому мы через tap. Она принимает данные и прокидывает дальше по флоу -writeErrorLogsSafe(formatedLogs); +app(process.env.FILE_PATH) \ No newline at end of file From 1b1c12b88c97e35c997a336c645f60c454d5931e Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Jul 2024 21:29:15 +0500 Subject: [PATCH 22/22] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index acef2e2..b99e7a7 100644 --- a/src/index.js +++ b/src/index.js @@ -64,6 +64,5 @@ const app = compose( readFileSafe, tap(logReadFile), ); -// в данном случае у нас здесь отсутствует логирование ошибок п.ч. оно ведет себя как процедура а не как функция т.е. она принимает в себя данные но ничего не возвращает поэтому мы через tap. Она принимает данные и прокидывает дальше по флоу app(process.env.FILE_PATH) \ No newline at end of file