mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 09:55:18 +00:00
Fix typo on path
This commit is contained in:
parent
e8cb3a630c
commit
fe23ae9fcc
@ -2,6 +2,9 @@ const winston = require('winston');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Checks if /var/log/wazuh exists on linux systems. If it doesn't exist, it will be created.
|
||||
*/
|
||||
const initDirectory = () => {
|
||||
if (!fs.existsSync('/var/log/wazuh') && process.platform === 'linux') {
|
||||
fs.mkdirSync('/var/log/wazuh');
|
||||
@ -9,6 +12,9 @@ const initDirectory = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Here we create the logger
|
||||
*/
|
||||
const wazuhlogger = winston.createLogger({
|
||||
level : 'info',
|
||||
format : winston.format.json(),
|
||||
@ -19,8 +25,15 @@ const wazuhlogger = winston.createLogger({
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* Prevents from exit on error related to the logger.
|
||||
*/
|
||||
wazuhlogger.exitOnError = false;
|
||||
|
||||
/**
|
||||
* Returns given file size in MB, if the file doesn't exist returns 0
|
||||
* @param {*} filename Path to the file
|
||||
*/
|
||||
const getFilesizeInMegaBytes = filename => {
|
||||
if (fs.existsSync(filename)) {
|
||||
const stats = fs.statSync(filename)
|
||||
@ -31,8 +44,11 @@ const getFilesizeInMegaBytes = filename => {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the wazuhapp.log file size is greater than 100MB, if so it rotates the file.
|
||||
*/
|
||||
const checkFiles = () => {
|
||||
if (getFilesizeInMegaBytes(path.join(__dirname, '../../error.log')) >= 100) {
|
||||
if (getFilesizeInMegaBytes(process.platform === 'linux' ? '/var/log/wazuh/wazuhapp.log' : path.join(__dirname, '../../wazuhapp.log')) >= 100) {
|
||||
fs.renameSync(
|
||||
process.platform === 'linux' ? '/var/log/wazuh/wazuhapp.log' : path.join(__dirname, '../../wazuhapp.log'),
|
||||
process.platform === 'linux' ? '/var/log/wazuh/wazuhapp.log' : path.join(__dirname, `../../wazuhapp.${new Date().getTime()}.log`)
|
||||
@ -40,6 +56,12 @@ const checkFiles = () => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Main function to add a new log
|
||||
* @param {*} location File where the log is being thrown
|
||||
* @param {*} message Message to show
|
||||
* @param {*} level Optional, default is 'error'
|
||||
*/
|
||||
const log = (location, message, level) => {
|
||||
initDirectory();
|
||||
checkFiles();
|
||||
|
Loading…
Reference in New Issue
Block a user