Skip to content

Commit

Permalink
Added File Logging using logFileUtility
Browse files Browse the repository at this point in the history
  • Loading branch information
TanmoySG authored May 19, 2022
1 parent ea2deea commit f2cc4bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions libraries/js/logsmith/lib/drivers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { consoleLogJSON, consoleLogStatement, prepareJSONLog, prepareStatementLog } from './logUtility.js';
import { ChalkLog, LogFormats } from './specs.js';
import { writeLogToFile } from './logFileUtility.js';

function transformStatementToJSON(statement) {
const transformedLog = {
Expand All @@ -8,17 +9,20 @@ function transformStatementToJSON(statement) {
return transformedLog
}

export function loggerRunner(logLevel, env, compiledLogPattern, logFormat, log) {

export function loggerRunner(logLevel, env, compiledLogPattern, logFormat, consoleOnly, logFilePath, log) {
if (typeof log == "string") {
log = transformStatementToJSON(log)
}
const chalkLog = ChalkLog[logLevel] || ChalkLog.CUSTOM
if (logFormat == LogFormats.JSON) {
prepareJSONLog(logLevel, log, env, function (LogJSON) {
writeLogToFile(LogJSON, logFilePath, consoleOnly)
consoleLogJSON(logLevel, chalkLog, LogJSON)
})
} else if (logFormat == LogFormats.STATEMENT) {
prepareStatementLog(logLevel, log, env, compiledLogPattern, function (LogStatement) {
prepareStatementLog(logLevel, log, env, compiledLogPattern, function (LogStatement, LogJSON) {
writeLogToFile(LogJSON, logFilePath, consoleOnly)
consoleLogStatement(logLevel, chalkLog, LogStatement)
})
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/js/logsmith/lib/logUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function prepareStatementLog(logLevel, log, env, logStatememtPattern, cal
...log
}
const LogStatement = logStatememtPattern(log)
callback(LogStatement)
callback(LogStatement, log)
}

export function consoleLogStatement(loglevel, chalkMode, LogStatement) {
Expand Down

0 comments on commit f2cc4bf

Please sign in to comment.