Skip to content

Commit

Permalink
v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Jan 22, 2022
1 parent 48edff6 commit d5c356d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 59 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

# v1.1.2 - 2022-01-22

## Bugfixes
- Fixed issues with logging
- Minor bugfixes

# v1.1.1 - 2022-01-22

## Other Changes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camera.ui",
"version": "1.1.1",
"version": "1.1.2",
"description": "NVR like user interface for RTSP capable cameras.",
"author": "SeydX (https://github.com/SeydX/camera.ui)",
"scripts": {
Expand Down
7 changes: 2 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ export default class CameraUI {
}

process.env.CUI_SERVICE_MODE = 2;

if (!logger) {
process.env.CUI_LOG_COLOR = 1;
process.env.CUI_LOG_TIMESTAMPS = 1;
}
process.env.CUI_LOG_COLOR = 1;
process.env.CUI_LOG_TIMESTAMPS = 1;

if (configJson.debug) {
process.env.CUI_LOG_DEBUG = 1;
Expand Down
114 changes: 63 additions & 51 deletions src/services/logger/logger.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ export default class LoggerService {
static socket;

constructor(logger) {
/**
* logger = {
* createUiLogger: (cameraUiLogger) => {},
* log: {
* prefix: 'MyLogger',
* info: console.info,
* warn: console.warn,
* error: console.error,
* debug: console.debug,
* },
* }
*/

if (process.env.CUI_LOG_COLOR === '1') {
chalk.level = 1;
}
Expand All @@ -61,6 +74,38 @@ export default class LoggerService {
fileName: 'camera.ui.log.txt',
});

if (logger?.log) {
LoggerService.#prefix = logger.log.prefix;
LoggerService.#logger = logger;
LoggerService.#customLogger = true;
LoggerService.#withPrefix = Boolean(logger.log.prefix);
}

// 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);

LoggerService.log = {
prefix: LoggerService.#prefix,
info: this.info,
Expand All @@ -69,46 +114,13 @@ export default class LoggerService {
debug: this.debug,
notify: this.notify,
toast: this.toast,
stream: LoggerService.#filelogger.stream,
db: LoggerService.#db,
};

if (logger) {
LoggerService.#prefix = logger.log.prefix || '';
LoggerService.#logger = logger;
LoggerService.#customLogger = true;
LoggerService.#withPrefix = false;

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();
});
if (logger?.createUiLogger) {
logger.createUiLogger(LoggerService.log);
}

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

return LoggerService.log;
}

Expand Down Expand Up @@ -172,52 +184,52 @@ export default class LoggerService {
}
}

static #logging(level, message, name) {
static #logging(level, message, name, fromExtern) {
if (level === LogLevel.DEBUG && !LoggerService.#debugEnabled) {
return;
}

let origMessage = message;
message = LoggerService.#formatMessage(message, name, level);
let formattedMessage = LoggerService.#formatMessage(message, name, level);

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

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

LoggerService.socket?.emit('logMessage', message);
LoggerService.socket?.emit('logMessage', formattedMessage);

if (LoggerService.#customLogger) {
return LoggerService.#logger.log[level](origMessage, name);
if (LoggerService.#customLogger && !fromExtern) {
return LoggerService.#logger.log[level](origMessage, name, false, true);
}

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

loggingFunction(message);
loggingFunction(formattedMessage);
}

info(message, name) {
LoggerService.#logging(LogLevel.INFO, message, name);
info(message, name, subprefix, fromExtern) {
LoggerService.#logging(LogLevel.INFO, message, name, false, fromExtern);
}

warn(message, name, subprefix) {
warn(message, name, subprefix, fromExtern) {
LoggerService.#logging(LogLevel.WARN, message, name);
LoggerService.#db(LogLevel.WARN, message, name, subprefix);
LoggerService.#db(LogLevel.WARN, message, name, subprefix, fromExtern);
}

error(message, name, subprefix) {
error(message, name, subprefix, fromExtern) {
LoggerService.#logging(LogLevel.ERROR, message, name);
LoggerService.#db(LogLevel.ERROR, message, name, subprefix);
LoggerService.#db(LogLevel.ERROR, message, name, subprefix, fromExtern);
}

debug(message, name) {
LoggerService.#logging(LogLevel.DEBUG, message, name);
debug(message, name, subprefix, fromExtern) {
LoggerService.#logging(LogLevel.DEBUG, message, name, false, fromExtern);
}

notify(notification) {
Expand Down
10 changes: 10 additions & 0 deletions ui/src/components/camera-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,23 @@ export default {
clearTimeout(this.snapshotTimeout);
this.snapshotTimeout = null;
}
if (this.snapshotTimerTimeout) {
clearTimeout(this.snapshotTimerTimeout);
this.snapshotTimerTimeout = null;
}
},
stopStream() {
if (this.player) {
this.player.destroy();
this.player = null;
}
if (this.streamTimeout) {
clearTimeout(this.streamTimeout);
this.streamTimeout = null;
}
this.$socket.client.emit('leave_stream', {
feed: this.camera.name,
});
Expand Down

0 comments on commit d5c356d

Please sign in to comment.