Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Jan 22, 2022
1 parent c32ad25 commit 518e111
Show file tree
Hide file tree
Showing 7 changed files with 634 additions and 619 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Changelog
All notable changes to this project will be documented in this file.

# v1.1.1 - 2022-01-22

## Other Changes
- Refactored logging into file
- Bump dependencies
- Minor improvements

## Bugfixes
- Minor bugfixes

# v1.1.0 - 2022-01-21

## Breaking Changes
Expand Down
1,064 changes: 532 additions & 532 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camera.ui",
"version": "1.1.0",
"version": "1.1.1",
"description": "NVR like user interface for RTSP capable cameras.",
"author": "SeydX (https://github.com/SeydX/camera.ui)",
"scripts": {
Expand All @@ -16,7 +16,7 @@
},
"main": "src/index.js",
"dependencies": {
"@aws-sdk/client-rekognition": "^3.47.1",
"@aws-sdk/client-rekognition": "^3.48.0",
"@seydx/lowdb": "^3.0.2",
"alexa-remote2": "^4.1.1",
"axios": "^0.25.0",
Expand Down Expand Up @@ -51,7 +51,7 @@
"smtp-server": "^3.9.0",
"socket.io": "4.4.1",
"socketio-jwt": "^4.6.2",
"systeminformation": "^5.10.5",
"systeminformation": "^5.10.7",
"swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.3.0",
"tar": "^6.1.11",
Expand Down
98 changes: 51 additions & 47 deletions src/services/logger/logger.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const LogLevel = {
DEBUG: 'debug',
};

const hookStream = (stream, callback) => {
const hook_writestream = (stream, callback) => {
var old_write = stream.write;

stream.write = (function (write) {
return function (string, encoding, fd) {
write.apply(stream, arguments); // comments this line if you don't want output in the console
write.apply(stream, arguments);
callback(string, encoding, fd);
};
})(stream.write);
Expand Down Expand Up @@ -48,8 +48,6 @@ export default class LoggerService {
chalk.level = 1;
}

//chalk.level = process.env.CUI_LOG_COLOR === '1' ? 1 : 0;

if (process.env.CUI_LOG_DEBUG === '1') {
LoggerService.#debugEnabled = true;
}
Expand All @@ -71,7 +69,7 @@ export default class LoggerService {
debug: this.debug,
notify: this.notify,
toast: this.toast,
file: this.file,
stream: LoggerService.#filelogger.stream,
db: LoggerService.#db,
};

Expand All @@ -84,12 +82,37 @@ export default class LoggerService {
if (logger.createUiLogger) {
logger.createUiLogger(LoggerService.log);
}
} else {
// eslint-disable-next-line no-unused-vars
const unhookStdout = hook_writestream(process.stdout, function (string, encoding, fd) {
LoggerService.#filelogger?.stream.write(string, encoding || 'utf8');
});

// eslint-disable-next-line no-unused-vars
const unhookStderr = hook_writestream(process.stderr, function (string, encoding, fd) {
LoggerService.#filelogger?.stream.write(string, encoding || 'utf8');
});

// eslint-disable-next-line no-unused-vars
LoggerService.#filelogger?.stream.once('error', function (error) {
unhookStdout();
unhookStderr();
});

LoggerService.#filelogger?.stream.once('close', function () {
unhookStdout();
unhookStderr();
});
}

setInterval(() => {
LoggerService.#filelogger.truncateFile();
}, 1000 * 60 * 60 * 2);

return LoggerService.log;
}

static #formatMessage(message, name) {
static #formatMessage(message, name, level) {
let formatted = '';

if (name) {
Expand All @@ -106,6 +129,18 @@ export default class LoggerService {
formatted += message;
}

switch (level) {
case LogLevel.WARN:
formatted = chalk.yellow(formatted);
break;
case LogLevel.ERROR:
formatted = chalk.red(formatted);
break;
case LogLevel.DEBUG:
formatted = chalk.gray(formatted);
break;
}

return formatted;
}

Expand Down Expand Up @@ -138,59 +173,33 @@ export default class LoggerService {
}

static #logging(level, message, name) {
if (LoggerService.#customLogger) {
return LoggerService.#logger.log[level](message, name);
}

if (level === LogLevel.DEBUG && !LoggerService.#debugEnabled) {
return;
}

//let fileMessage = (message = LoggerService.#formatMessage(message, name));
message = LoggerService.#formatMessage(message, name);

const logger = LoggerService.#logger;
let loggingFunction = logger.log;

switch (level) {
case LogLevel.WARN:
message = chalk.yellow(message);
loggingFunction = logger.warn;
break;
case LogLevel.ERROR:
message = chalk.red(message);
loggingFunction = logger.error;
break;
case LogLevel.DEBUG:
message = chalk.gray(message);
break;
}
let origMessage = message;
message = LoggerService.#formatMessage(message, name, level);

if (LoggerService.#withPrefix) {
message = chalk.magenta(`[${LoggerService.#prefix}] `) + message;
//fileMessage = `[${this.#prefix}] ${fileMessage}`;
}

if (LoggerService.#timestampEnabled) {
const date = new Date();
message = chalk.white(`[${date.toLocaleString()}] `) + message;
//fileMessage = `[${date.toLocaleString()}] ${fileMessage}`;
}

const unhookStdout = hookStream(process.stdout, () => {
LoggerService.#filelogger.log(message);
LoggerService.socket?.emit('logMessage', message);
});
LoggerService.socket?.emit('logMessage', message);

const unhookStderr = hookStream(process.stderr, () => {
LoggerService.#filelogger.log(message);
LoggerService.socket?.emit('logMessage', message);
});
if (LoggerService.#customLogger) {
return LoggerService.#logger.log[level](origMessage, name);
}

loggingFunction(message);
const logger = LoggerService.#logger;
const loggingFunction =
level === LogLevel.WARN ? logger.warn : level === LogLevel.ERROR ? logger.error : logger.log;

unhookStdout();
unhookStderr();
loggingFunction(message);
}

info(message, name) {
Expand Down Expand Up @@ -237,9 +246,4 @@ export default class LoggerService {
LoggerService.#logging(LogLevel.DEBUG, `Toasting new message: ${message}`);
LoggerService.socket?.emit('toast', message);
}

file(message) {
LoggerService.#filelogger.log(message);
LoggerService.socket?.emit('logMessage', message);
}
}
50 changes: 25 additions & 25 deletions src/services/logger/utils/filelogger.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,7 @@ export default class FileLogger {
}
}

#createLogDirectory() {
try {
fs.mkdirSync(this.options.path, {
recursive: true,
mode: '0775',
});
} catch {
return false;
}

return true;
}

async #toFile(string) {
try {
await this.#truncateFile();
} catch {
//ignore
}

const output = `${string}\r\n`;
this.stream.write(output);
}

async #truncateFile() {
async truncateFile() {
if (!(await fs.pathExists(this.logPath))) {
return;
}
Expand All @@ -87,4 +63,28 @@ export default class FileLogger {
await fs.write(logFileHandle, logBuffer);
await fs.close(logFileHandle);
}

#createLogDirectory() {
try {
fs.mkdirSync(this.options.path, {
recursive: true,
mode: '0775',
});
} catch {
return false;
}

return true;
}

async #toFile(string) {
/*try {
await this.#truncateFile();
} catch {
//ignore
}*/

const output = `${string}\r\n`;
this.stream.write(output);
}
}
22 changes: 11 additions & 11 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
"dependencies": {
"@mdi/js": "^6.5.95",
"axios": "^0.25.0",
"chart.js": "2.8.0",
"chart.js": "3.7.0",
"draggabilly": "^3.0.0",
"file-saver": "^2.0.5",
"gridstack": "^5.0.0",
"jsmpeg-fast-player": "^0.2.0",
"register-service-worker": "^1.7.2",
"socket.io-client": "4.4.1",
"swiper": "4.5.1",
"swiper": "7.4.1",
"v-calendar": "^2.3.4",
"v-jsoneditor": "^1.4.5",
"vue": "^2.6.14",
"vue-chartjs": "3.4.2",
"vue-chartjs": "3.5.1",
"vue-i18n": "^8.27.0",
"vue-infinite-loading": "^2.4.5",
"vue-inline-svg": "^2.1.0",
Expand All @@ -44,20 +44,20 @@
"@vue/cli-plugin-router": "^4.5.15",
"@vue/cli-plugin-vuex": "^4.5.15",
"@vue/cli-service": "^4.5.15",
"@vue/eslint-config-prettier": "6.0.0",
"autoprefixer": "9.8.8",
"@vue/eslint-config-prettier": "7.0.0",
"autoprefixer": "10.4.2",
"babel-eslint": "^10.1.0",
"core-js": "^3.20.3",
"eslint": "6.7.2",
"eslint-plugin-prettier": "3.3.1",
"eslint-plugin-vue": "6.2.2",
"eslint": "8.7.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-vue": "8.3.0",
"minify-css-string": "^1.0.0",
"postcss": "7.0.39",
"postcss": "8.4.5",
"prettier": "^2.5.1",
"pug": "^3.0.2",
"pug-plain-loader": "^1.1.0",
"sass": "1.32.0",
"sass-loader": "10.0.0",
"sass": "1.49.0",
"sass-loader": "12.4.0",
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.17",
"vue-cli-plugin-vuetify": "^2.4.5",
"vue-template-compiler": "^2.6.14",
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/console.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default {
this.fitAddon?.fit();
const log = await getLog();
const message = log.data + '\r\n';
const message = log.data.replace(/[\n]+/g, '\r\n');
this.term?.write(message);
this.fitAddon?.fit();
Expand Down

0 comments on commit 518e111

Please sign in to comment.