forked from Red-Stream-Y3/AgroHelp
-
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 branch 'main' into snyk-upgrade-5495070ffeefe0c498486db1fffcbe9d
- Loading branch information
Showing
63 changed files
with
2,864 additions
and
2,334 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
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
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
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
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,41 @@ | ||
/** | ||
* This file is used to log info to a file | ||
* Three log levels exist: info, warning, error | ||
*/ | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export const LOG = { | ||
INFO: 'info', | ||
WARNING: 'warning', | ||
ERROR: 'error', | ||
}; | ||
const __dirname = path.resolve(); | ||
|
||
const log = (level, message) => { | ||
const logMessage = `${new Date().toISOString()} [${level.toUpperCase()}]: ${message}\n`; | ||
|
||
const logPath = path.join(__dirname, '../logs'); | ||
if (!fs.existsSync(logPath)) { | ||
fs.mkdirSync(logPath); | ||
} | ||
|
||
const logFile = path.join(logPath, `${level}.log`); | ||
fs.appendFileSync(logFile, logMessage); | ||
console.log(logMessage); | ||
}; | ||
|
||
const info = (message) => { | ||
log(LOG.INFO, message); | ||
}; | ||
|
||
const warning = (message) => { | ||
log(LOG.WARNING, message); | ||
}; | ||
|
||
const error = (message) => { | ||
log(LOG.ERROR, message); | ||
}; | ||
|
||
export default { info, warning, error }; |
Oops, something went wrong.