grix-connector
Version:
Connect local AI coding agents (Claude, Codex, Gemini, Qwen, DeepSeek, Cursor, OpenCode, Pi, OpenHuman, Reasonix) to the Grix scheduling platform. Also serves as an OpenClaw plugin for Grix channel transport.
7 lines (6 loc) • 2.42 kB
JavaScript
import{createWriteStream as D,mkdirSync as T,existsSync as v,readdirSync as w,statSync as R,unlinkSync as x}from"node:fs";import{join as p}from"node:path";import{resolveRuntimePaths as I}from"../config/paths.js";const f=I(),l={base:f.rootDir,config:f.configDir,log:f.logDir,data:f.dataDir};function j(){for(const e of Object.values(l))v(e)||T(e,{recursive:!0})}const a={trace:0,debug:1,info:2,warn:3,error:4};function L(e,n){if(!e)return n;const r=e.trim().toLowerCase();return r in a?r:n}function b(e){const n=new Map;if(!e)return n;for(const r of e.split(",")){const t=r.indexOf("=");if(t<0)continue;const u=r.slice(0,t).trim(),N=L(r.slice(t+1),"info");u&&n.set(u,N)}return n}let m=L(process.env.GRIX_CONNECTOR_LOG_LEVEL,"info");const O=b(process.env.GRIX_CONNECTOR_LOG_TAG_LEVELS);function G(e){return O.get(e)??m}function o(e,n){return a[n]>=a[G(e)]}function F(e){m=e}function P(e,n){O.set(e,n)}let g=null,d="";const y="GRIX_CONNECTOR_LOG_RETENTION_DAYS",C=14;function h(){const e=process.env[y],n=e?Number.parseInt(e,10):Number.NaN;return Number.isFinite(n)&&n>0?n:C}function S(){return new Date().toISOString().slice(0,10)}function $(){const e=Date.now()-h()*24*60*60*1e3;let n;try{n=w(l.log)}catch{return}for(const r of n){if(!r.startsWith("grix-connector-")||!r.includes(".log"))continue;const t=p(l.log,r);try{R(t).mtimeMs<e&&x(t)}catch{}}}function _(e){try{g?.end()}catch{}const n=p(l.log,`grix-connector-${e}.log`);g=D(n,{flags:"a"}),d=e,$()}function W(){_(S())}function A(){return new Date().toISOString().slice(11,19)}let E=!0;function M(e){E=e}function i(e,n){E&&(e==="warn"?console.warn(n):e==="error"?console.error(n):console.log(n))}function c(e){try{const n=S();n!==d&&_(n),g?.write(e)}catch{}}function s(e,n,r,t){const u=e==="info"?"":`${e.toUpperCase()} `;return`${A()} [${n}] ${u}${r}${t.length?" "+t.map(String).join(" "):""}`}const U={trace(e,n,...r){if(!o(e,"trace"))return;const t=s("trace",e,n,r);i("trace",t),c(t+`
`)},debug(e,n,...r){if(!o(e,"debug"))return;const t=s("debug",e,n,r);i("debug",t),c(t+`
`)},info(e,n,...r){if(!o(e,"info"))return;const t=s("info",e,n,r);i("info",t),c(t+`
`)},warn(e,n,...r){if(!o(e,"warn"))return;const t=s("warn",e,n,r);i("warn",t),c(t+`
`)},error(e,n,...r){if(!o(e,"error"))return;const t=s("error",e,n,r);i("error",t),c(t+`
`)}};export{l as GRIX_PATHS,j as ensureGrixDirs,W as initLogger,U as log,M as setConsoleOutput,F as setLogLevel,P as setTagLogLevel};