File tree Expand file tree Collapse file tree 1 file changed +28
-4
lines changed
Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -11,11 +11,36 @@ const MAX_LENGTH = 65535 // Max total log size is sometimes 100k (sometimes 6553
1111const BUFFER = 1000 // Buffer for context, etc.
1212
1313// Ensure debug directory exists for local environment
14- const debugDir = path . join ( __dirname , '../../../debug' )
15- if (
14+ let debugDir : string | null | undefined
15+ function getDebugDir ( ) : string | null {
16+ if ( debugDir !== undefined ) {
17+ return debugDir
18+ }
19+ debugDir = __dirname
20+ while ( true ) {
21+ if ( fs . existsSync ( path . join ( debugDir , '.git' ) ) ) {
22+ break
23+ }
24+ const parent = path . dirname ( debugDir )
25+ if ( parent === debugDir ) {
26+ debugDir = null
27+ console . error ( 'Failed to find git root directory for logger' )
28+ break
29+ }
30+ }
31+
32+ return debugDir
33+ }
34+
35+ setLocalDebugDir: if (
1636 env . NEXT_PUBLIC_CB_ENVIRONMENT === 'dev' &&
1737 process . env . CODEBUFF_GITHUB_ACTIONS !== 'true'
1838) {
39+ const debugDir = getDebugDir ( )
40+ if ( ! debugDir ) {
41+ break setLocalDebugDir
42+ }
43+
1944 try {
2045 fs . mkdirSync ( debugDir , { recursive : true } )
2146 } catch ( err ) {
@@ -33,8 +58,7 @@ const pinoLogger = pino(
3358 } ,
3459 timestamp : ( ) => `,"timestamp":"${ new Date ( Date . now ( ) ) . toISOString ( ) } "` ,
3560 } ,
36- env . NEXT_PUBLIC_CB_ENVIRONMENT === 'dev' &&
37- process . env . CODEBUFF_GITHUB_ACTIONS !== 'true'
61+ debugDir
3862 ? pino . transport ( {
3963 target : 'pino/file' ,
4064 options : {
You can’t perform that action at this time.
0 commit comments