Socket
Socket
Sign inDemoInstall

electron-log

Package Overview
Dependencies
Maintainers
1
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-log - npm Package Compare versions

Comparing version 4.0.0-beta.3 to 4.0.0-beta.4

2

CHANGELOG.md

@@ -9,2 +9,4 @@ # Changelog

`const log = electronLog.create('loggerId')`
- add object `log.functions` which allows to safety exports logger functions

@@ -11,0 +13,0 @@ ### File transport

2

package.json
{
"name": "electron-log",
"version": "4.0.0-beta.3",
"version": "4.0.0-beta.4",
"description": "Just a very simple logging module for your Electron application",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -48,2 +48,6 @@ # electron-log

### `nodeIntegration`
If you've got an error in a renderer process similar to `require is not defined`
read [the nodeIntegration section](docs/node-integration.md).
### Transport

@@ -126,2 +130,17 @@

### Overriding console.log
Sometimes it's helpful to use electron-log instead of default `console`. It's
pretty easy:
```js
console.log = log.log;
```
If you would like to override other functions like `error`, `warn` and so on:
```js
Object.assign(console, log.functions);
```
### Colors

@@ -128,0 +147,0 @@

@@ -161,7 +161,6 @@ 'use strict';

function sendIpcToMain(channel, message) {
if (!electron || !electron.ipcRenderer) {
return;
var ipc = getIpc();
if (ipc) {
ipc.send(channel, message);
}
electron.ipcRenderer.send(channel, message);
}

@@ -168,0 +167,0 @@

@@ -315,64 +315,71 @@ declare namespace ElectronLog {

interface ElectronLog {
interface LogFunctions {
/**
* Transport instances
* Log an error message
*/
transports: Transports;
error (...params: any[]): void;
/**
* Array with all attached hooks
* Log a warning message
*/
hooks: Hook[];
warn (...params: any[]): void;
/**
* Array with all available levels
* Log an informational message
*/
levels: Levels;
info (...params: any[]): void;
/**
* Variables used by formatters
* Log a verbose message
*/
variables: Variables;
verbose (...params: any[]): void;
/**
* Catch and log unhandled errors/rejected promises
* Log a debug message
*/
catchErrors (options?: CatchErrorsOptions): CatchErrorsResult;
debug (...params: any[]): void;
/**
* Log an error message
* Log a silly message
*/
error (...params: any[]): void;
silly (...params: any[]): void;
/**
* Log a warning message
* Shortcut to info
*/
warn (...params: any[]): void;
log (...params: any[]): void;
}
interface ElectronLog extends LogFunctions {
/**
* Log an informational message
* Object contained only log functions
*/
info (...params: any[]): void;
functions: LogFunctions;
/**
* Log a verbose message
* Transport instances
*/
verbose (...params: any[]): void;
transports: Transports;
/**
* Log a debug message
* Array with all attached hooks
*/
debug (...params: any[]): void;
hooks: Hook[];
/**
* Log a silly message
* Array with all available levels
*/
silly (...params: any[]): void;
levels: Levels;
/**
* Shortcut to info
* Variables used by formatters
*/
log (...params: any[]): void;
variables: Variables;
/**
* Catch and log unhandled errors/rejected promises
*/
catchErrors (options?: CatchErrorsOptions): CatchErrorsResult;
/**
* Create a new electron-log instance

@@ -379,0 +386,0 @@ */

@@ -25,2 +25,3 @@ 'use strict';

create: create,
functions: {},
hooks: [],

@@ -44,7 +45,9 @@ isDev: electronApi.isDev(),

instance[level] = log.bind(null, instance, level);
instance.functions[level] = instance[level];
});
instance.log = log.bind(null, instance, 'info');
instance.functions.log = instance.log;
return instance;
}

@@ -41,3 +41,3 @@ 'use strict';

var template = data[0];
if (typeof template !== 'string' || !message.variables) {
if (typeof template !== 'string') {
return data;

@@ -69,5 +69,5 @@ }

function templateText(data, message) {
function templateText(data) {
var template = data[0];
if (typeof template !== 'string' || !message.variables) {
if (typeof template !== 'string') {
return data;

@@ -74,0 +74,0 @@ }

@@ -27,3 +27,3 @@ 'use strict';

* @param {string} filePath
* @param {IWriteOptions} [writeOptions]
* @param {WriteOptions} [writeOptions]
* @param {boolean} [writeAsync]

@@ -59,3 +59,3 @@ */

/**
* @type {IWriteOptions}
* @type {WriteOptions}
* @private

@@ -78,3 +78,6 @@ */

try {
fs.unlinkSync(this.path);
fs.writeFileSync(this.path, '', {
mode: this.writeOptions.mode,
flag: 'w',
});
this.reset();

@@ -92,2 +95,16 @@ return true;

File.prototype.crop = function (bytesAfter) {
try {
var content = readFileSyncFromEnd(this.path, bytesAfter || 4096);
this.clear();
this.writeLine('[log cropped]' + os.EOL + content);
} catch (e) {
this.emit(
'error',
new Error('Couldn\'t crop file ' + this.path + '. ' + e.message),
this
);
}
};
File.prototype.toString = function () {

@@ -186,2 +203,3 @@ return this.path;

NullFile.prototype.clear = function () {};
NullFile.prototype.crop = function () {};
NullFile.prototype.writeLine = function () {};

@@ -209,3 +227,3 @@ NullFile.prototype.getSize = function () { return 0 };

* @param {string} filePath
* @param {IWriteOptions} [writeOptions]
* @param {WriteOptions} [writeOptions]
* @param {boolean} [async]

@@ -236,3 +254,3 @@ * @return {File}

* @param {string} filePath
* @param {IWriteOptions} writeOptions
* @param {WriteOptions} writeOptions
* @param {boolean} async

@@ -291,1 +309,15 @@ * @return {File}

}
function readFileSyncFromEnd(filePath, bytesCount) {
var buffer = Buffer.alloc(bytesCount);
var stats = fs.statSync(filePath);
var readLength = Math.min(stats.size, bytesCount);
var offset = Math.max(0, stats.size - bytesCount);
var fd = fs.openSync(filePath, 'r');
var totalBytes = fs.readSync(fd, buffer, 0, readLength, offset);
fs.closeSync(fd);
return buffer.toString('utf8', 0, totalBytes);
}

@@ -64,8 +64,10 @@ 'use strict';

function archiveLog(file) {
file = file.toString();
var info = path.parse(file);
var oldPath = file.toString();
var inf = path.parse(oldPath);
try {
fs.renameSync(file, path.join(info.dir, info.name + '.old' + info.ext));
fs.renameSync(oldPath, path.join(inf.dir, inf.name + '.old' + inf.ext));
} catch (e) {
logConsole('Could not rotate log', e);
var quarterOfMaxSize = Math.round(transport.maxSize / 4);
file.crop(Math.min(quarterOfMaxSize, 256 * 1024));
}

@@ -98,3 +100,3 @@ }

/**
* @param {IPathVariables} vars
* @param {PathVariables} vars
*/

@@ -101,0 +103,0 @@ function resolvePath(vars) {

@@ -73,3 +73,3 @@ 'use strict';

* @param {string} platform
* @return {IPathVariables}
* @return {PathVariables}
*/

@@ -76,0 +76,0 @@ function getPathVariables(platform) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc