UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.66 kB
import e from"./console-transport/index.mjs";import{tryGetContext as t}from"hono/context-storage";const n={silent:-1,error:0,warn:1,info:2,debug:3};let r=!1,i=[];const a=(e,t)=>{try{console.error(`Lucid logger transport failed to ${e}`,t)}catch{}},o=(e,t)=>n[t]<=n[e],s=()=>t()?.get(`requestId`),c=(e,t)=>{if(!e.destroyed)try{let n=e.transport.write(t);typeof n==`object`&&n&&`then`in n&&typeof n.then==`function`&&Promise.resolve(n).catch(e=>{a(`write`,e)})}catch(e){a(`write`,e)}},l=async(e,t)=>{if(e.destroyed)return;let n=e.transport[t];if(n)try{await n()}catch(e){a(t,e)}},u=e=>({get level(){return e.level},error:t=>{m(e,`error`,t)},warn:t=>{m(e,`warn`,t)},info:t=>{m(e,`info`,t)},debug:t=>{m(e,`debug`,t)},flush:()=>l(e,`flush`)}),d=()=>({destroyed:!1,level:`info`,transport:e()});let f=d(),p=u(f);const m=(e,t,n)=>{if(!r&&!o(e.level,t))return;let a=n.requestId??s(),l={...n,...a?{requestId:a}:{},level:t,timestamp:new Date().toISOString()};if(r){i.push(l);return}c(e,l)},h=async e=>{e.destroyed||=(await l(e,`flush`),await l(e,`destroy`),!0)},g=async t=>{await h(f);let n=t?.level??`info`;return f={destroyed:!1,level:n,transport:t?.transport??e({verbose:n===`debug`})},p=u(f),p},_=()=>{r=!0},v=async()=>{r=!1;let e=i;i=[],f.destroyed&&(f=d(),p=u(f));for(let t of e)o(f.level,t.level)&&c(f,t);await l(f,`flush`)},y=async()=>{await h(f)},b=()=>p,x={get level(){return b().level},error:e=>b().error(e),warn:e=>b().warn(e),info:e=>b().info(e),debug:e=>b().debug(e),flush:()=>b().flush()};export{x as default,y as destroyLogger,b as getLogger,g as initializeLogger,_ as startLoggerBuffering,v as stopLoggerBuffering}; //# sourceMappingURL=index.mjs.map