Comparing version 0.0.4 to 0.0.5
@@ -21,3 +21,2 @@ import Elysia from 'elysia'; | ||
}; | ||
export declare const logester: (logger?: typeof Logestic.defaultLogger) => Elysia; | ||
export declare class Logestic { | ||
@@ -24,0 +23,0 @@ private requestedAttrs; |
@@ -1,2 +0,81 @@ | ||
// @bun | ||
import E from"elysia";var F={common:{uses:["ip","method","path","status","contentLength"],format:({ip:A,method:S,path:v,status:w,contentLength:x})=>{return`${A} ${S} ${v} ${w} ${x}`}}},I=(A=k.defaultLogger)=>{return new k(A).instance};class k{requestedAttrs;logger;instance;static defaultLogger=(A)=>{console.log(A)};constructor(A=k.defaultLogger){this.requestedAttrs={},this.logger=A,this.instance=new E({name:"logestic"})}use(A){if(A instanceof Array){for(let S of A)this.requestedAttrs[S]=!0;return this}return this.requestedAttrs[A]=!0,this}static preset(A,S=k.defaultLogger){const{uses:v,format:w}=F[A];return new k(S).use(v).custom(w)}custom(A){return this.instance=this.instance.onAfterHandle(({request:S,path:v,body:w,query:x,set:z})=>{let j={};for(let C in this.requestedAttrs)switch(C){case"ip":j.ip=S.headers.get("x-forwarded-for")||"<ip>";break;case"method":j.method=S.method;break;case"path":j.path=v;break;case"body":j.body=w;break;case"query":j.query=x;break;case"time":j.time=new Date;break;case"contentLength":j.contentLength=Number(S.headers.get("content-length"));break;case"status":j.status=z.status;break;case"referer":j.referer=S.headers.get("referer")||"<referer>";break;case"userAgent":j.userAgent=S.headers.get("user-agent")||"<user-agent>";break}const B=A(j);this.logger(B)}),this.instance}log(A){this.logger(A)}}export{I as logester,k as Logestic}; | ||
import Elysia from 'elysia'; | ||
const presetDef = { | ||
common: { | ||
uses: ['ip', 'method', 'path', 'status', 'contentLength'], | ||
format: ({ ip, method, path, status, contentLength }) => { | ||
return `${ip} ${method} ${path} ${status} ${contentLength}`; | ||
} | ||
} | ||
}; | ||
export class Logestic { | ||
constructor(logger = Logestic.defaultLogger) { | ||
this.requestedAttrs = {}; | ||
this.logger = logger; | ||
this.instance = new Elysia({ name: 'logestic' }); | ||
} | ||
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); | ||
} | ||
} | ||
Logestic.defaultLogger = (msg) => { | ||
console.log(msg); | ||
}; |
{ | ||
"name": "logestic", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"license": "MIT", | ||
"author": "Nishant Aanjaney Jalan <cybercoder.nishant@gmail.com>", | ||
"description": "An advanced and customisable logging library for ElysiaJS", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"/dist" | ||
], | ||
"exports": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.js", | ||
"node": "./dist/index.js", | ||
"default": "./dist/index.js" | ||
}, | ||
"keywords": [ | ||
@@ -23,2 +14,3 @@ "logging", | ||
], | ||
"homepage": "https://github.com/cybercoder-naj/logestic.git", | ||
"repository": { | ||
@@ -28,21 +20,28 @@ "type": "git", | ||
}, | ||
"author": "Nishant Aanjaney Jalan <cybercoder.nishant@gmail.com>", | ||
"license": "MIT", | ||
"bugs": "https://github.com/cybercoder-naj/logestic/issues", | ||
"files": ["dist"], | ||
"exports": { | ||
".": { | ||
"import": "./src/index.ts", | ||
"require": "./dist/index.js", | ||
"bun": "./dist/index.ts", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"module": "src/index.ts", | ||
"type": "module", | ||
"devDependencies": { | ||
"@elysiajs/eden": "0.8.1", | ||
"typescript": "^5.0.0", | ||
"bun-types": "latest" | ||
"scripts": { | ||
"build": "rimraf dist && tsc", | ||
"test": "bun test" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0", | ||
"elysia": "0.8.17" | ||
"elysia": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf dist && bun build src/index.ts --outdir ./dist --target bun --minify --external elysia && tsc", | ||
"test": "bun test" | ||
"devDependencies": { | ||
"@elysiajs/eden": "0.8.1", | ||
"bun-types": "latest", | ||
"rimraf": "^5.0.5", | ||
"typescript": "^5.0.0" | ||
}, | ||
"homepage": "https://github.com/cybercoder-naj/logestic.git", | ||
"bugs": "https://github.com/cybercoder-naj/logestic/issues", | ||
"publishConfig": { | ||
@@ -49,0 +48,0 @@ "access": "public" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6159
114
4