New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

logestic

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logestic - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

3

dist/index.d.ts

@@ -24,4 +24,3 @@ import Elysia from 'elysia';

private logger;
instance: Elysia;
static defaultLogger: (msg: string) => void;
private static defaultLogger;
constructor(logger?: typeof Logestic.defaultLogger);

@@ -28,0 +27,0 @@ use(attr: keyof Attribute): Logestic;

@@ -1,81 +0,84 @@

import Elysia from 'elysia';
const presetDef = {
// @bun
import H from 'elysia';
var I = {
common: {
uses: ['ip', 'method', 'path', 'status', 'contentLength'],
format: ({ ip, method, path, status, contentLength }) => {
return `${ip} ${method} ${path} ${status} ${contentLength}`;
}
uses: ['ip', 'method', 'path', 'status', 'contentLength'],
format: ({ ip: P, method: k, path: j, status: w, contentLength: B }) => {
return `${P} ${k} ${j} ${w} ${B}`;
}
}
};
export class Logestic {
constructor(logger = Logestic.defaultLogger) {
this.requestedAttrs = {};
this.logger = logger;
this.instance = new Elysia({ name: 'logestic' });
},
J = (P, k) => {
const { request: j, path: w, body: B, query: C, set: F } = P;
let v = {};
for (let G in k)
switch (G) {
case 'ip':
v.ip = j.headers.get('x-forwarded-for') || '<ip?>';
break;
case 'method':
v.method = j.method;
break;
case 'path':
v.path = w;
break;
case 'body':
v.body = B;
break;
case 'query':
v.query = C;
break;
case 'time':
v.time = new Date();
break;
case 'contentLength':
v.contentLength = Number(j.headers.get('content-length'));
break;
case 'status':
v.status = F.status;
break;
case 'referer':
v.referer = j.headers.get('referer') || '<referer?>';
break;
case 'userAgent':
v.userAgent = j.headers.get('user-agent') || '<user-agent?>';
break;
}
return v;
};
class z {
requestedAttrs;
logger;
static defaultLogger = P => {
console.log(P);
};
constructor(P = z.defaultLogger) {
(this.requestedAttrs = {}), (this.logger = P);
}
use(P) {
if (Array.isArray(P)) {
for (let k of P) this.requestedAttrs[k] = !0;
return this;
}
use(attrs) {
if (attrs instanceof Array) {
for (const attr of attrs) {
this.requestedAttrs[attr] = true;
}
return this;
}
// Single attribute
this.requestedAttrs[attrs] = true;
return this;
}
static preset(name, logger = Logestic.defaultLogger) {
const { uses, format } = presetDef[name];
return new Logestic(logger).use(uses).custom(format);
}
custom(format) {
this.instance = this.instance.onAfterHandle(({ request, path, body, query, set }) => {
let attrs = {};
for (const key in this.requestedAttrs) {
const k = key;
switch (k) {
case 'ip':
attrs.ip = request.headers.get('x-forwarded-for') || '<ip>';
break;
case 'method':
attrs.method = request.method;
break;
case 'path':
attrs.path = path;
break;
case 'body':
attrs.body = body;
break;
case 'query':
attrs.query = query;
break;
case 'time':
attrs.time = new Date();
break;
case 'contentLength':
attrs.contentLength = Number(request.headers.get('content-length'));
break;
case 'status':
attrs.status = set.status;
break;
case 'referer':
attrs.referer = request.headers.get('referer') || '<referer>';
break;
case 'userAgent':
attrs.userAgent =
request.headers.get('user-agent') || '<user-agent>';
break;
}
}
const msg = format(attrs);
this.logger(msg);
});
return this.instance;
}
log(msg) {
this.logger(msg);
}
return (this.requestedAttrs[P] = !0), this;
}
static preset(P, k = z.defaultLogger) {
const { uses: j, format: w } = I[P];
return new z(k).use(j).custom(w);
}
custom(P) {
return new H()
.onAfterHandle({ as: 'global' }, k => {
let j = J(k, this.requestedAttrs);
const w = P(j);
this.log(w);
})
.onError({ as: 'global' }, ({ request: k, error: j }) => {
this.log(`Error: ${k.method} ${k.url} ${j.message}`);
});
}
log(P) {
this.logger(P);
}
}
Logestic.defaultLogger = (msg) => {
console.log(msg);
};
export { z as Logestic };
{
"name": "logestic",
"version": "0.0.7",
"license": "MIT",
"version": "0.1.0",
"author": "Nishant Aanjaney Jalan <cybercoder.nishant@gmail.com>",

@@ -15,2 +14,4 @@ "description": "An advanced and customisable logging library for ElysiaJS",

"homepage": "https://github.com/cybercoder-naj/logestic.git",
"bugs": "https://github.com/cybercoder-naj/logestic/issues",
"license": "MIT",
"repository": {

@@ -20,7 +21,6 @@ "type": "git",

},
"bugs": "https://github.com/cybercoder-naj/logestic/issues",
"files": [
"dist/index.js",
"dist/index.d.ts"
"dist"
],
"main": "dist/index.js",
"module": "src/index.ts",

@@ -27,0 +27,0 @@ "type": "module",

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