Socket
Book a DemoInstallSign in
Socket

errsole-sqlite

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

errsole-sqlite - npm Package Compare versions

Comparing version

to
3.0.0

130

lib/index.js

@@ -62,6 +62,6 @@ /**

this.logsTable = `${tablePrefix}_logs_v2`;
this.logsTable = `${tablePrefix}_logs_v3`;
this.usersTable = `${tablePrefix}_users`;
this.configTable = `${tablePrefix}_config`;
this.notificationsTable = `${tablePrefix}_notifications`;
this.notificationsTable = `${tablePrefix}_notifications_v2`;

@@ -166,6 +166,6 @@ this.name = require('../package.json').name;

`CREATE INDEX IF NOT EXISTS idx_${this.logsTable}_source_level_id ON ${this.logsTable} (source, level, id)`,
`CREATE INDEX IF NOT EXISTS idx_${this.logsTable}_source_level_timestamp ON ${this.logsTable} (source, level, timestamp)`,
`CREATE INDEX IF NOT EXISTS idx_${this.logsTable}_hostname_pid_id ON ${this.logsTable} (hostname, pid, id)`,
`CREATE INDEX IF NOT EXISTS idx_${this.logsTable}_id ON ${this.logsTable} (errsole_id)`,
`CREATE INDEX IF NOT EXISTS idx_${this.notificationsTable}_hostname_hashed_message_created ON ${this.notificationsTable} (hostname, hashed_message, created_at)`,
`CREATE INDEX IF NOT EXISTS idx_${this.logsTable}_source_level_timestamp_id ON ${this.logsTable} (source, level, timestamp, id)`,
`CREATE INDEX IF NOT EXISTS idx_${this.logsTable}_timestamp_id ON ${this.logsTable} (timestamp, id)`,
`CREATE INDEX IF NOT EXISTS idx_${this.logsTable}_errsole_id ON ${this.logsTable} (errsole_id)`,
`CREATE INDEX IF NOT EXISTS idx_${this.notificationsTable}_hashed_message_created_at ON ${this.notificationsTable} (hashed_message, created_at)`,
`CREATE INDEX IF NOT EXISTS idx_${this.notificationsTable}_created_at ON ${this.notificationsTable} (created_at)`

@@ -187,3 +187,3 @@ ];

async ensureLogsTTL () {
const DEFAULT_LOGS_TTL = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds
const DEFAULT_LOGS_TTL = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
const configResult = await this.getConfig('logsTTL');

@@ -322,15 +322,3 @@ if (!configResult.item) {

async getHostnames () {
const query = `
SELECT DISTINCT hostname
FROM ${this.logsTable}
WHERE hostname IS NOT NULL AND hostname != ''
`;
return new Promise((resolve, reject) => {
this.db.all(query, [], (err, rows) => {
if (err) return reject(err);
const hostnames = rows.map(row => row.hostname).sort();
resolve({ items: hostnames });
});
});
return { items: [] };
}

@@ -353,37 +341,6 @@

const values = [];
let sortOrder = 'DESC';
let orderBy = 'id DESC';
let shouldReverse = true;
// Apply filters
if (filters.hostname) {
whereClauses.push('hostname = ?');
values.push(filters.hostname);
}
if (filters.pid) {
whereClauses.push('pid = ?');
values.push(filters.pid);
}
if (filters.sources && filters.sources.length > 0) {
whereClauses.push('source IN (?)');
values.push(filters.sources);
}
if (filters.levels && filters.levels.length > 0) {
whereClauses.push('level IN (?)');
values.push(filters.levels);
}
if (filters.hostnames && filters.hostnames.length > 0) {
const placeholders = filters.hostnames.map(() => '?').join(', ');
whereClauses.push(`hostname IN (${placeholders})`);
values.push(...filters.hostnames);
}
if (filters.level_json && filters.level_json.length > 0) {
const levelConditions = filters.level_json.map(levelObj => '(source = ? AND level = ?)');
whereClauses.push(`(${levelConditions.join(' OR ')})`);
filters.level_json.forEach(levelObj => {
values.push(levelObj.source, levelObj.level);
});
}
if (filters.level_json || filters.errsole_id) {

@@ -406,7 +363,6 @@ const orConditions = [];

}
if (filters.lt_id) {
whereClauses.push('id < ?');
values.push(filters.lt_id);
sortOrder = 'DESC';
orderBy = 'id DESC';
shouldReverse = true;

@@ -416,3 +372,3 @@ } else if (filters.gt_id) {

values.push(filters.gt_id);
sortOrder = 'ASC';
orderBy = 'id ASC';
shouldReverse = false;

@@ -423,3 +379,3 @@ } else if (filters.lte_timestamp || filters.gte_timestamp) {

values.push(new Date(filters.lte_timestamp));
sortOrder = 'DESC';
orderBy = 'timestamp DESC, id DESC';
shouldReverse = true;

@@ -430,3 +386,3 @@ }

values.push(new Date(filters.gte_timestamp));
sortOrder = 'ASC';
orderBy = 'timestamp ASC, id ASC';
shouldReverse = false;

@@ -437,3 +393,3 @@ }

const whereClause = whereClauses.length ? `WHERE ${whereClauses.join(' AND ')}` : '';
const query = `SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM ${this.logsTable} ${whereClause} ORDER BY id ${sortOrder} LIMIT ?`;
const query = `SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM ${this.logsTable} ${whereClause} ORDER BY ${orderBy} LIMIT ?`;
values.push(filters.limit);

@@ -466,37 +422,6 @@

const values = searchTerms.map(term => `%${term}%`);
let sortOrder = 'DESC';
let orderBy = 'id DESC';
let shouldReverse = true;
// Apply filters
if (filters.hostname) {
whereClauses.push('hostname = ?');
values.push(filters.hostname);
}
if (filters.pid) {
whereClauses.push('pid = ?');
values.push(filters.pid);
}
if (filters.hostnames && filters.hostnames.length > 0) {
const placeholders = filters.hostnames.map(() => '?').join(', ');
whereClauses.push(`hostname IN (${placeholders})`);
values.push(...filters.hostnames);
}
if (filters.sources && filters.sources.length > 0) {
whereClauses.push(`source IN (${filters.sources.map(() => '?').join(', ')})`);
values.push(...filters.sources);
}
if (filters.levels && filters.levels.length > 0) {
whereClauses.push(`level IN (${filters.levels.map(() => '?').join(', ')})`);
values.push(...filters.levels);
}
if (filters.level_json && filters.level_json.length > 0) {
const levelConditions = filters.level_json.map(() => '(source = ? AND level = ?)');
whereClauses.push(`(${levelConditions.join(' OR ')})`);
filters.level_json.forEach(levelObj => {
values.push(levelObj.source, levelObj.level);
});
}
if (filters.level_json || filters.errsole_id) {

@@ -519,7 +444,6 @@ const orConditions = [];

}
if (filters.lt_id) {
whereClauses.push('id < ?');
values.push(filters.lt_id);
sortOrder = 'DESC';
orderBy = 'id DESC';
shouldReverse = true;

@@ -530,3 +454,3 @@ }

values.push(filters.gt_id);
sortOrder = 'ASC';
orderBy = 'id ASC';
shouldReverse = false;

@@ -538,3 +462,3 @@ }

values.push(new Date(filters.lte_timestamp));
sortOrder = 'DESC';
orderBy = 'timestamp DESC, id DESC';
shouldReverse = true;

@@ -545,3 +469,3 @@ }

values.push(new Date(filters.gte_timestamp));
sortOrder = 'ASC';
orderBy = 'timestamp ASC, id ASC';
shouldReverse = false;

@@ -567,3 +491,3 @@ }

const limitClause = `LIMIT ${filters.limit}`;
const query = `SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM ${this.logsTable} ${whereClause} ORDER BY id ${sortOrder} ${limitClause}`;
const query = `SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM ${this.logsTable} ${whereClause} ORDER BY ${orderBy} ${limitClause}`;

@@ -610,3 +534,3 @@ return new Promise((resolve, reject) => {

const DEFAULT_LOGS_TTL = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds
const DEFAULT_LOGS_TTL = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds

@@ -692,3 +616,3 @@ try {

SELECT * FROM ${this.notificationsTable}
WHERE hostname = ? AND hashed_message = ?
WHERE hashed_message = ?
ORDER BY created_at DESC

@@ -716,6 +640,8 @@ LIMIT 1;

const countTodayNotificationsQuery = `
SELECT COUNT(*) AS notificationCount
FROM ${this.notificationsTable}
WHERE hashed_message = ? AND DATE(created_at) = DATE('now', 'localtime');
SELECT COUNT(*) AS notificationCount FROM ${this.notificationsTable}
WHERE hashed_message = ?
AND created_at >= DATE('now', 'start of day', 'utc')
AND created_at < DATE('now', 'start of day', 'utc', '+1 day');
`;
const todayNotificationCount = await new Promise((resolve, reject) => {

@@ -758,3 +684,3 @@ this.db.get(countTodayNotificationsQuery, [hashedMessage], (err, result) => {

const DEFAULT_NOTIFICATIONS_TTL = 30 * 24 * 60 * 60 * 1000;
const DEFAULT_NOTIFICATIONS_TTL = 7 * 24 * 60 * 60 * 1000;

@@ -761,0 +687,0 @@ try {

{
"name": "errsole-sqlite",
"version": "2.3.0",
"version": "3.0.0",
"description": "SQLite storage plugin for Errsole",

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

@@ -8,8 +8,12 @@ # errsole-sqlite

Errsole is a Node.js logger with a built-in web dashboard. In this dashboard, you can easily view, filter, and search your app logs.
Errsole is an open-source logger for Node.js applications. It comes with a built-in log viewer to view, filter, and search your application logs.
If your application uses SQLite as its database or if you prefer storing your application logs in SQLite, you should install both the `errsole` and `errsole-sqlite` modules. This setup allows you to store your application logs directly in your SQLite database.
## Setup
[Errsole with SQLite](https://github.com/errsole/errsole.js/blob/master/docs/sqlite-storage.md)
## Full Documentation
[https://github.com/errsole/errsole.js](https://github.com/errsole/errsole.js)
SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.