diff --git a/README.md b/README.md index dbd55d6..ee6ec40 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Практикум по функциональному программированию ШРИ -Применение приемов функционального программирования, на ральной задаче. +Применение приемов функционального программирования, на реальной задаче. ### Файлы 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..b99e7a7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,43 +1,32 @@ -import { - allPass, - anyPass, - applySpec, - compose, - curry, - equals, - filter, - map, - match, - nth, - partial, - partialRight, - prop, - tap, - 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(); +const formatLogs = partialRight(JSON.stringify, [null, 2]); +const writeErrorLogs = partial(writeFile,['errorsLog.json', '../']); + const curriedLog = curry(log); -const logRed = curriedLog('red'); const logGreen = curriedLog('green'); +const logRed = curriedLog('red'); + const logError = logRed('Error'); const logReadFile = logGreen('Read file'); const logWriteFile = logGreen('Write file'); -const formatLogs = partialRight(JSON.stringify, [null, 2]); -const writeErrorLogs = partial(writeFile, ['errorsLog.json', '../']); - 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); +const getParsedLogMessage = nth(4); + +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'); @@ -46,28 +35,26 @@ const isErrorLog = compose(isError, getType); const isWarnLog = compose(isWarn, getType); const isInfraComponentLog = compose(isInfraComponent, getComponent); -const isErrorOrWarnLog = anyPass([isErrorLog, isWarnLog]); +const isErrorOrWarnLog = anyPass([isWarnLog, isErrorLog]); const isInfraErrorLog = allPass([isErrorOrWarnLog, isInfraComponentLog]); -const splitFileByLine = match(/[^\r\n]+/g); -const parseLog = match(/([\d-:,\s]+)\s\(.+\)\s(\w+)\s+\(([^)]+)\)\s(.+)/); -const getParsedLogInfo = applySpec({ +const getLogInfo = applySpec({ time: getParsedLogTime, type: getParsedLogType, component: getParsedLogComponent, - message: getParsedLogMassage, + message: getParsedLogMessage, }); -const createSafeFunction = (fn) => tryCatch(fn, logErrorMessage); -const readFileSafe = createSafeFunction(readFile); -const writeErrorLogsSafe = createSafeFunction(writeErrorLogs); - const getInfraErrorsLog = compose( filter(isInfraErrorLog), - map(getParsedLogInfo), + map(getLogInfo), map(parseLog), ); +const createSafeFunction = (fn) => tryCatch(fn, logErrorMessage); +const readFileSafe = createSafeFunction(readFile); +const writeErrorLogsSafe = createSafeFunction(writeErrorLogs); + const app = compose( writeErrorLogsSafe, tap(logWriteFile), @@ -78,4 +65,4 @@ const app = compose( tap(logReadFile), ); -app(process.env.FILE_PATH); +app(process.env.FILE_PATH) \ No newline at end of file