@@ -360,7 +360,7 @@ app.get('/listogs/youtube/callback', async (req, res) => {
360360 const redirectUrl = isDev ? 'http://localhost:3001/listogs' : 'https://martinbarker.me/listogs' ;
361361 res . redirect ( redirectUrl ) ;
362362 } catch ( error ) {
363- console . error ( '\nError during YouTube authentication:' , error . message ) ;
363+ logger . error ( 'Error during YouTube authentication:' , error . message ) ;
364364 res . status ( 500 ) . send ( 'Authentication failed.' ) ;
365365 }
366366} ) ;
@@ -398,18 +398,18 @@ app.get('/generateURL', (req, res) => {
398398 }
399399 res . status ( 200 ) . json ( { url : signInUrl } ) ;
400400 } catch ( error ) {
401- console . error ( 'Error generating sign-in URL:' , error . message ) ;
401+ logger . error ( 'Error generating sign-in URL:' , error . message ) ;
402402 res . status ( 500 ) . json ( { error : error . message } ) ;
403403 }
404404} ) ;
405405
406406// Route to handle Discogs search
407407app . post ( '/discogsAuth' , async ( req , res ) => {
408- console . log ( "🎶 [POST /discogsAuth] Hit" , req . body ) ;
408+ logger . info ( "🎶 [POST /discogsAuth] Hit" , req . body ) ;
409409 const { query } = req . body ;
410410
411411 if ( ! query ) {
412- console . error ( "❌ No query provided in the request body." ) ;
412+ logger . error ( "❌ No query provided in the request body." ) ;
413413 return res . status ( 400 ) . json ( { error : 'No query provided.' } ) ;
414414 }
415415
@@ -801,7 +801,7 @@ const DISCOGS_AUTHORIZE_URL = 'https://discogs.com/oauth/authorize';
801801// Function to make a single Discogs API request
802802async function fetchDiscogsData ( type , id ) {
803803 try {
804- console . log ( `🔍 [fetchDiscogsData] Starting fetch for type=${ type } , id=${ id } ` ) ;
804+ logger . debug ( `🔍 [fetchDiscogsData] Starting fetch for type=${ type } , id=${ id } ` ) ;
805805
806806 let url = '' ;
807807 if ( type === 'label' ) {
@@ -816,51 +816,51 @@ async function fetchDiscogsData(type, id) {
816816 url = `${ DISCOGS_API_URL } /masters/${ id } ` ;
817817 } else {
818818 const errorMsg = `Invalid type provided: ${ type } . Valid types are: label, artist, list, release, master` ;
819- console . error ( `❌ [fetchDiscogsData] ${ errorMsg } ` ) ;
819+ logger . error ( `❌ [fetchDiscogsData] ${ errorMsg } ` ) ;
820820 throw new Error ( errorMsg ) ;
821821 }
822822
823- console . log ( `🌐 [fetchDiscogsData] Making request to URL: ${ url } ` ) ;
824- console . log ( `📋 [fetchDiscogsData] Request headers:` , { 'User-Agent' : USER_AGENT } ) ;
823+ logger . debug ( `🌐 [fetchDiscogsData] Making request to URL: ${ url } ` ) ;
824+ logger . debug ( `📋 [fetchDiscogsData] Request headers:` , { 'User-Agent' : USER_AGENT } ) ;
825825
826826 const response = await axios . get ( url , {
827827 headers : { 'User-Agent' : USER_AGENT } ,
828828 timeout : 30000 , // 30 second timeout
829829 } ) ;
830830
831- console . log ( `📊 [fetchDiscogsData] Response status: ${ response . status } ` ) ;
832- console . log ( `📊 [fetchDiscogsData] Response headers:` , response . headers ) ;
833- console . log ( `📊 [fetchDiscogsData] Response data keys:` , Object . keys ( response . data || { } ) ) ;
831+ logger . debug ( `📊 [fetchDiscogsData] Response status: ${ response . status } ` ) ;
832+ logger . debug ( `📊 [fetchDiscogsData] Response headers:` , response . headers ) ;
833+ logger . debug ( `📊 [fetchDiscogsData] Response data keys:` , Object . keys ( response . data || { } ) ) ;
834834
835835 // For release/master, return full JSON
836836 if ( type === 'release' || type === 'master' ) {
837- console . log ( `✅ [fetchDiscogsData] Returning full data for ${ type } ` ) ;
837+ logger . debug ( `✅ [fetchDiscogsData] Returning full data for ${ type } ` ) ;
838838 return response . data ;
839839 }
840840
841841 // Return only the first item from the response for other types
842842 if ( response . data . releases && response . data . releases . length > 0 ) {
843- console . log ( `✅ [fetchDiscogsData] Found ${ response . data . releases . length } releases, returning first one` ) ;
843+ logger . debug ( `✅ [fetchDiscogsData] Found ${ response . data . releases . length } releases, returning first one` ) ;
844844 return response . data . releases [ 0 ] ;
845845 } else if ( response . data . items && response . data . items . length > 0 ) {
846- console . log ( `✅ [fetchDiscogsData] Found ${ response . data . items . length } items, returning first one` ) ;
846+ logger . debug ( `✅ [fetchDiscogsData] Found ${ response . data . items . length } items, returning first one` ) ;
847847 return response . data . items [ 0 ] ;
848848 } else {
849- console . log ( `⚠️ [fetchDiscogsData] No items found in response` ) ;
849+ logger . warn ( `⚠️ [fetchDiscogsData] No items found in response` ) ;
850850 return { message : 'No items found.' } ;
851851 }
852852 } catch ( error ) {
853- console . error ( `❌ [fetchDiscogsData] Detailed error information:` ) ;
854- console . error ( ` - Error type: ${ error . constructor . name } ` ) ;
855- console . error ( ` - Error message: ${ error . message } ` ) ;
856- console . error ( ` - Error code: ${ error . code || 'N/A' } ` ) ;
857- console . error ( ` - Error status: ${ error . response ?. status || 'N/A' } ` ) ;
858- console . error ( ` - Error statusText: ${ error . response ?. statusText || 'N/A' } ` ) ;
859- console . error ( ` - Request URL: ${ error . config ?. url || 'N/A' } ` ) ;
860- console . error ( ` - Request method: ${ error . config ?. method || 'N/A' } ` ) ;
861- console . error ( ` - Request headers:` , error . config ?. headers || 'N/A' ) ;
862- console . error ( ` - Response data:` , error . response ?. data || 'N/A' ) ;
863- console . error ( ` - Stack trace:` , error . stack ) ;
853+ logger . error ( `❌ [fetchDiscogsData] Detailed error information:` ) ;
854+ logger . error ( ` - Error type: ${ error . constructor . name } ` ) ;
855+ logger . error ( ` - Error message: ${ error . message } ` ) ;
856+ logger . error ( ` - Error code: ${ error . code || 'N/A' } ` ) ;
857+ logger . error ( ` - Error status: ${ error . response ?. status || 'N/A' } ` ) ;
858+ logger . error ( ` - Error statusText: ${ error . response ?. statusText || 'N/A' } ` ) ;
859+ logger . error ( ` - Request URL: ${ error . config ?. url || 'N/A' } ` ) ;
860+ logger . error ( ` - Request method: ${ error . config ?. method || 'N/A' } ` ) ;
861+ logger . error ( ` - Request headers:` , error . config ?. headers || 'N/A' ) ;
862+ logger . error ( ` - Response data:` , error . response ?. data || 'N/A' ) ;
863+ logger . error ( ` - Stack trace:` , error . stack ) ;
864864
865865 // Create a more detailed error message
866866 let detailedMessage = `Failed to fetch Discogs data for ${ type } /${ id } ` ;
@@ -975,7 +975,7 @@ async function fetchVideoIds(releaseId) {
975975// Route to handle Discogs API requests
976976app . post ( '/discogsFetch' , async ( req , res ) => {
977977 const requestId = Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) ;
978- console . log ( `📡 [POST /discogsFetch] Request ${ requestId } started` , {
978+ logger . info ( `📡 [POST /discogsFetch] Request ${ requestId } started` , {
979979 body : req . body ,
980980 headers : req . headers ,
981981 ip : req . ip ,
@@ -987,7 +987,7 @@ app.post('/discogsFetch', async (req, res) => {
987987 // Validate input parameters
988988 if ( ! type || ! id ) {
989989 const errorMsg = `Missing required parameters. Received: type=${ type } , id=${ id } ` ;
990- console . error ( `❌ [POST /discogsFetch] Request ${ requestId } - ${ errorMsg } ` ) ;
990+ logger . error ( `❌ [POST /discogsFetch] Request ${ requestId } - ${ errorMsg } ` ) ;
991991 return res . status ( 400 ) . json ( {
992992 error : 'Type and ID are required.' ,
993993 details : errorMsg ,
@@ -1000,7 +1000,7 @@ app.post('/discogsFetch', async (req, res) => {
10001000 const validTypes = [ 'label' , 'artist' , 'list' , 'release' , 'master' ] ;
10011001 if ( ! validTypes . includes ( type ) ) {
10021002 const errorMsg = `Invalid type '${ type } '. Valid types are: ${ validTypes . join ( ', ' ) } ` ;
1003- console . error ( `❌ [POST /discogsFetch] Request ${ requestId } - ${ errorMsg } ` ) ;
1003+ logger . error ( `❌ [POST /discogsFetch] Request ${ requestId } - ${ errorMsg } ` ) ;
10041004 return res . status ( 400 ) . json ( {
10051005 error : 'Invalid type parameter.' ,
10061006 details : errorMsg ,
@@ -1012,9 +1012,9 @@ app.post('/discogsFetch', async (req, res) => {
10121012 // Check if secrets are initialized
10131013 if ( ! secretsInitialized ) {
10141014 const errorMsg = 'Server secrets not initialized. AWS secrets may not be loaded.' ;
1015- console . error ( `❌ [POST /discogsFetch] Request ${ requestId } - ${ errorMsg } ` ) ;
1016- console . error ( ` - secretsInitialized: ${ secretsInitialized } ` ) ;
1017- console . error ( ` - secretsLastRefresh: ${ secretsLastRefresh } ` ) ;
1015+ logger . error ( `❌ [POST /discogsFetch] Request ${ requestId } - ${ errorMsg } ` ) ;
1016+ logger . error ( ` - secretsInitialized: ${ secretsInitialized } ` ) ;
1017+ logger . error ( ` - secretsLastRefresh: ${ secretsLastRefresh } ` ) ;
10181018 return res . status ( 503 ) . json ( {
10191019 error : 'Server not ready. Secrets not initialized.' ,
10201020 details : errorMsg ,
@@ -1029,11 +1029,11 @@ app.post('/discogsFetch', async (req, res) => {
10291029 // Check if Discogs credentials are available
10301030 if ( ! discogsConsumerKey || ! discogsConsumerSecret ) {
10311031 const errorMsg = 'Discogs API credentials not available. Check AWS Secrets Manager configuration.' ;
1032- console . error ( `❌ [POST /discogsFetch] Request ${ requestId } - ${ errorMsg } ` ) ;
1033- console . error ( ` - discogsConsumerKey exists: ${ ! ! discogsConsumerKey } ` ) ;
1034- console . error ( ` - discogsConsumerSecret exists: ${ ! ! discogsConsumerSecret } ` ) ;
1035- console . error ( ` - discogsConsumerKey length: ${ discogsConsumerKey ?. length || 0 } ` ) ;
1036- console . error ( ` - discogsConsumerSecret length: ${ discogsConsumerSecret ?. length || 0 } ` ) ;
1032+ logger . error ( `❌ [POST /discogsFetch] Request ${ requestId } - ${ errorMsg } ` ) ;
1033+ logger . error ( ` - discogsConsumerKey exists: ${ ! ! discogsConsumerKey } ` ) ;
1034+ logger . error ( ` - discogsConsumerSecret exists: ${ ! ! discogsConsumerSecret } ` ) ;
1035+ logger . error ( ` - discogsConsumerKey length: ${ discogsConsumerKey ?. length || 0 } ` ) ;
1036+ logger . error ( ` - discogsConsumerSecret length: ${ discogsConsumerSecret ?. length || 0 } ` ) ;
10371037 return res . status ( 500 ) . json ( {
10381038 error : 'Discogs credentials not configured.' ,
10391039 details : errorMsg ,
@@ -1048,8 +1048,8 @@ app.post('/discogsFetch', async (req, res) => {
10481048 }
10491049
10501050 try {
1051- console . log ( `🔍 [POST /discogsFetch] Request ${ requestId } - Starting fetchDiscogsData for type=${ type } , id=${ id } ` ) ;
1052- console . log ( `📋 [POST /discogsFetch] Request ${ requestId } - Environment:` , {
1051+ logger . info ( `🔍 [POST /discogsFetch] Request ${ requestId } - Starting fetchDiscogsData for type=${ type } , id=${ id } ` ) ;
1052+ logger . debug ( `📋 [POST /discogsFetch] Request ${ requestId } - Environment:` , {
10531053 NODE_ENV : process . env . NODE_ENV ,
10541054 DISCOGS_API_URL : DISCOGS_API_URL ,
10551055 USER_AGENT : USER_AGENT
@@ -1059,11 +1059,11 @@ app.post('/discogsFetch', async (req, res) => {
10591059 const data = await fetchDiscogsData ( type , id ) ;
10601060 const duration = Date . now ( ) - startTime ;
10611061
1062- console . log ( `✅ [POST /discogsFetch] Request ${ requestId } - Success in ${ duration } ms` ) ;
1062+ logger . info ( `✅ [POST /discogsFetch] Request ${ requestId } - Success in ${ duration } ms` ) ;
10631063
10641064 // Log response summary
10651065 if ( data && data . id ) {
1066- console . log ( `📊 [POST /discogsFetch] Request ${ requestId } - Response summary:` , {
1066+ logger . info ( `📊 [POST /discogsFetch] Request ${ requestId } - Response summary:` , {
10671067 type,
10681068 id,
10691069 responseId : data . id ,
@@ -1073,14 +1073,14 @@ app.post('/discogsFetch', async (req, res) => {
10731073 duration : `${ duration } ms`
10741074 } ) ;
10751075 } else if ( data && data . message ) {
1076- console . log ( `📊 [POST /discogsFetch] Request ${ requestId } - Response message:` , {
1076+ logger . info ( `📊 [POST /discogsFetch] Request ${ requestId } - Response message:` , {
10771077 type,
10781078 id,
10791079 message : data . message ,
10801080 duration : `${ duration } ms`
10811081 } ) ;
10821082 } else {
1083- console . log ( `📊 [POST /discogsFetch] Request ${ requestId } - Response received:` , {
1083+ logger . info ( `📊 [POST /discogsFetch] Request ${ requestId } - Response received:` , {
10841084 type,
10851085 id,
10861086 responseType : typeof data ,
@@ -1092,15 +1092,15 @@ app.post('/discogsFetch', async (req, res) => {
10921092 } catch ( error ) {
10931093 const duration = Date . now ( ) - Date . now ( ) ; // This will be 0, but shows the pattern
10941094
1095- console . error ( `❌ [POST /discogsFetch] Request ${ requestId } - Detailed error information:` ) ;
1096- console . error ( ` - Request parameters: type=${ type } , id=${ id } ` ) ;
1097- console . error ( ` - Error type: ${ error . constructor . name } ` ) ;
1098- console . error ( ` - Error message: ${ error . message } ` ) ;
1099- console . error ( ` - Error code: ${ error . code || 'N/A' } ` ) ;
1100- console . error ( ` - Error status: ${ error . statusCode || error . response ?. status || 'N/A' } ` ) ;
1101- console . error ( ` - Request URL: ${ error . url || error . config ?. url || 'N/A' } ` ) ;
1102- console . error ( ` - Stack trace:` , error . stack ) ;
1103- console . error ( ` - Original error:` , error . originalError ?. message || 'N/A' ) ;
1095+ logger . error ( `❌ [POST /discogsFetch] Request ${ requestId } - Detailed error information:` ) ;
1096+ logger . error ( ` - Request parameters: type=${ type } , id=${ id } ` ) ;
1097+ logger . error ( ` - Error type: ${ error . constructor . name } ` ) ;
1098+ logger . error ( ` - Error message: ${ error . message } ` ) ;
1099+ logger . error ( ` - Error code: ${ error . code || 'N/A' } ` ) ;
1100+ logger . error ( ` - Error status: ${ error . statusCode || error . response ?. status || 'N/A' } ` ) ;
1101+ logger . error ( ` - Request URL: ${ error . url || error . config ?. url || 'N/A' } ` ) ;
1102+ logger . error ( ` - Stack trace:` , error . stack ) ;
1103+ logger . error ( ` - Original error:` , error . originalError ?. message || 'N/A' ) ;
11041104
11051105 // Create comprehensive error response
11061106 const errorResponse = {
@@ -1585,15 +1585,16 @@ server.listen(port, async () => {
15851585 await initializeSecrets ( ) ;
15861586 await initializeOAuth ( ) ;
15871587 if ( loadTokens ( ) ) {
1588- console . log ( 'Using existing tokens for authentication.' ) ;
1588+ logger . info ( 'Using existing tokens for authentication.' ) ;
15891589 } else {
1590- console . log ( 'No tokens found. Please visit the sign-in URL to authenticate.' ) ;
1590+ logger . info ( 'No tokens found. Please visit the sign-in URL to authenticate.' ) ;
15911591 }
1592- console . log ( `Server is running on port ${ port } ` ) ;
1592+ logger . info ( `🚀 Server is running on port ${ port } ` ) ;
1593+ logger . info ( `📊 Server ready to accept connections` ) ;
15931594 } catch ( error ) {
1594- console . error ( "Failed to initialize server components:" , error ) ;
1595- console . error ( "Server will continue running with limited functionality." ) ;
1596- console . log ( `Server is running on port ${ port } (with initialization errors)` ) ;
1595+ logger . error ( "Failed to initialize server components:" , error ) ;
1596+ logger . error ( "Server will continue running with limited functionality." ) ;
1597+ logger . warn ( `Server is running on port ${ port } (with initialization errors)` ) ;
15971598 }
15981599} ) ;
15991600
@@ -2135,7 +2136,7 @@ app.get('/internal-api/youtube/callback', async (req, res) => {
21352136
21362137// Get YouTube authentication status
21372138app . get ( '/youtube/authStatus' , ( req , res ) => {
2138- console . log ( "🔍 [GET /youtube/authStatus] Hit" ) ;
2139+ logger . info ( "🔍 [GET /youtube/authStatus] Hit" ) ;
21392140
21402141 const youtubeAuth = req . session ?. youtubeAuth ;
21412142 const isAuthenticated = youtubeAuth ?. isAuthenticated || false ;
@@ -2161,7 +2162,7 @@ app.get('/youtube/authStatus', (req, res) => {
21612162
21622163// Get YouTube authentication status (production route)
21632164app . get ( '/internal-api/youtube/authStatus' , ( req , res ) => {
2164- console . log ( "🔍 [GET /internal-api/youtube/authStatus] Hit" ) ;
2165+ logger . info ( "🔍 [GET /internal-api/youtube/authStatus] Hit" ) ;
21652166
21662167 const youtubeAuth = req . session ?. youtubeAuth ;
21672168 const isAuthenticated = youtubeAuth ?. isAuthenticated || false ;
@@ -2187,7 +2188,7 @@ app.get('/internal-api/youtube/authStatus', (req, res) => {
21872188
21882189// Clear YouTube authentication
21892190app . post ( '/youtube/clearAuth' , ( req , res ) => {
2190- console . log ( "🧹 [POST /youtube/clearAuth] Hit" ) ;
2191+ logger . info ( "🧹 [POST /youtube/clearAuth] Hit" ) ;
21912192
21922193 try {
21932194 // Clear session data
@@ -2238,7 +2239,7 @@ app.post('/internal-api/youtube/clearAuth', (req, res) => {
22382239// Exchange auth code for tokens
22392240app . post ( '/youtube/exchangeCode' , ( req , res ) => {
22402241 if ( process . env . NODE_ENV === 'development' ) {
2241- console . log ( "🔄 [POST /youtube/exchangeCode] Hit" ) ;
2242+ logger . info ( "🔄 [POST /youtube/exchangeCode] Hit" ) ;
22422243 }
22432244
22442245 try {
@@ -2330,7 +2331,7 @@ app.post('/internal-api/youtube/exchangeCode', (req, res) => {
23302331// Create YouTube playlist
23312332app . post ( '/youtube/createPlaylist' , ( req , res ) => {
23322333 if ( process . env . NODE_ENV === 'development' ) {
2333- console . log ( "🎵 [POST /youtube/createPlaylist] Hit" ) ;
2334+ logger . info ( "🎵 [POST /youtube/createPlaylist] Hit" ) ;
23342335 }
23352336
23362337 try {
@@ -4338,4 +4339,4 @@ app.post('/discogs/api', async (req, res) => {
43384339
43394340 res . status ( 500 ) . json ( { error : err . message } ) ;
43404341 }
4341- } ) ;
4342+ } ) ;
0 commit comments