@@ -5,6 +5,7 @@ import { CustomFormatResource } from "./src/__generated__/generated-sonarr-api";
5
5
import { configureRadarrApi , configureSonarrApi , getArrApi , unsetApi } from "./src/api" ;
6
6
import { getConfig } from "./src/config" ;
7
7
import { calculateCFsToManage , loadLocalCfs , loadServerCustomFormats , manageCf , mergeCfSources } from "./src/custom-formats" ;
8
+ import { logHeading , logger } from "./src/logger" ;
8
9
import { calculateQualityDefinitionDiff , loadQualityDefinitionFromServer } from "./src/quality-definitions" ;
9
10
import {
10
11
calculateQualityProfilesDiff ,
@@ -27,12 +28,17 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
27
28
} ;
28
29
29
30
if ( value . include ) {
30
- console . log ( `Recyclarr Includes:\n${ value . include . map ( ( e ) => e . template ) . join ( "\n" ) } ` ) ;
31
+ logger . info ( `Recyclarr includes ${ value . include . length } templates` ) ;
32
+ logger . debug (
33
+ value . include . map ( ( e ) => e . template ) ,
34
+ "Included templates" ,
35
+ ) ;
36
+
31
37
value . include . forEach ( ( e ) => {
32
38
const template = recyclarrTemplateMap . get ( e . template ) ;
33
39
34
40
if ( ! template ) {
35
- console . log ( `Unknown recyclarr template requested: ${ e . template } ` ) ;
41
+ logger . info ( `Unknown recyclarr template requested: ${ e . template } ` ) ;
36
42
return ;
37
43
}
38
44
@@ -72,18 +78,18 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
72
78
73
79
const idsToManage = calculateCFsToManage ( recylarrMergedTemplates ) ;
74
80
75
- console . log ( `Stuff to manage: ${ Array . from ( idsToManage ) } `) ;
81
+ logger . debug ( Array . from ( idsToManage ) , `CustomFormats to manage `) ;
76
82
77
83
const serverCFs = await loadServerCustomFormats ( ) ;
78
- console . log ( `CFs on server: ${ serverCFs . length } `) ;
84
+ logger . info ( `CustomFormats on server: ${ serverCFs . length } `) ;
79
85
80
86
const serverCFMapping = serverCFs . reduce ( ( p , c ) => {
81
87
p . set ( c . name ! , c ) ;
82
88
return p ;
83
89
} , new Map < string , CustomFormatResource > ( ) ) ;
84
90
85
91
await manageCf ( mergedCFs , serverCFMapping , idsToManage ) ;
86
- console . log ( `CustomFormats should be in sync ` ) ;
92
+ logger . info ( `CustomFormats synchronized ` ) ;
87
93
88
94
const qualityDefinition = recylarrMergedTemplates . quality_definition ?. type ;
89
95
@@ -109,18 +115,18 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
109
115
110
116
if ( changeMap . size > 0 ) {
111
117
if ( IS_DRY_RUN ) {
112
- console . log ( "DryRun: Would update QualityDefinitions." ) ;
118
+ logger . info ( "DryRun: Would update QualityDefinitions." ) ;
113
119
} else {
114
- console . log ( `Diffs in quality definitions found` , changeMap . values ( ) ) ;
120
+ logger . info ( `Diffs in quality definitions found` , changeMap . values ( ) ) ;
115
121
await api . v3QualitydefinitionUpdateUpdate ( restData as any ) ; // Ignore types
116
- console . log ( `Updated QualityDefinitions` ) ;
122
+ logger . info ( `Updated QualityDefinitions` ) ;
117
123
}
118
124
} else {
119
- console . log ( `QualityDefinitions do not need update!` ) ;
125
+ logger . info ( `QualityDefinitions do not need update!` ) ;
120
126
}
121
127
122
128
if ( create . length > 0 ) {
123
- console . log ( `Currently not implemented this case for quality definitions.` ) ;
129
+ logger . info ( `Currently not implemented this case for quality definitions.` ) ;
124
130
}
125
131
}
126
132
@@ -169,29 +175,29 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
169
175
} ) ;
170
176
}
171
177
172
- console . log ( `QPs : Create: ${ create . length } , Update: ${ changedQPs . length } , Unchanged: ${ noChanges . length } `) ;
178
+ logger . info ( `QualityProfiles : Create: ${ create . length } , Update: ${ changedQPs . length } , Unchanged: ${ noChanges . length } `) ;
173
179
174
180
if ( ! IS_DRY_RUN ) {
175
181
for ( const element of create ) {
176
182
try {
177
183
const newProfile = await api . v3QualityprofileCreate ( element as any ) ; // Ignore types
178
- console . log ( `Created QualityProfile: ${ newProfile . data . name } ` ) ;
184
+ logger . info ( `Created QualityProfile: ${ newProfile . data . name } ` ) ;
179
185
} catch ( error : any ) {
180
186
let message ;
181
187
182
188
if ( error . response ) {
183
- console . log ( error . response ) ;
189
+ logger . info ( error . response ) ;
184
190
// The request was made and the server responded with a status code
185
191
// that falls out of the range of 2xx
186
192
message = `Failed creating QualityProfile (${ element . name } ): Data ${ JSON . stringify ( error . response . data ) } ` ;
187
193
} else if ( error . request ) {
188
194
// The request was made but no response was received
189
195
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
190
196
// http.ClientRequest in node.js
191
- console . log ( error . request ) ;
197
+ logger . info ( error . request ) ;
192
198
} else {
193
199
// Something happened in setting up the request that triggered an Error
194
- console . log ( "Error" , error . message ) ;
200
+ logger . info ( "Error" , error . message ) ;
195
201
}
196
202
197
203
throw new Error ( message ) ;
@@ -201,7 +207,7 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
201
207
for ( const element of changedQPs ) {
202
208
try {
203
209
const newProfile = await api . v3QualityprofileUpdate ( "" + element . id , element as any ) ; // Ignore types
204
- console . log ( `Updated QualityProfile: ${ newProfile . data . name } ` ) ;
210
+ logger . info ( `Updated QualityProfile: ${ newProfile . data . name } ` ) ;
205
211
} catch ( error : any ) {
206
212
let message ;
207
213
@@ -213,10 +219,10 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
213
219
// The request was made but no response was received
214
220
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
215
221
// http.ClientRequest in node.js
216
- console . log ( error . request ) ;
222
+ logger . info ( error . request ) ;
217
223
} else {
218
224
// Something happened in setting up the request that triggered an Error
219
- console . log ( "Error" , error . message ) ;
225
+ logger . info ( "Error" , error . message ) ;
220
226
}
221
227
222
228
throw new Error ( message ) ;
@@ -242,9 +248,11 @@ const run = async () => {
242
248
243
249
// TODO currently this has to be run sequentially because of the centrally configured api
244
250
251
+ logHeading ( `Processing Sonarr ...` ) ;
252
+
245
253
for ( const instanceName in applicationConfig . sonarr ) {
246
254
const instance = applicationConfig . sonarr [ instanceName ] ;
247
- console . log ( `Processing Sonarr Instance: ${ instanceName } ` ) ;
255
+ logger . info ( `Processing Sonarr Instance: ${ instanceName } ` ) ;
248
256
await configureSonarrApi ( instance . base_url , instance . api_key ) ;
249
257
await pipeline ( instance , "SONARR" ) ;
250
258
unsetApi ( ) ;
@@ -256,11 +264,13 @@ const run = async () => {
256
264
applicationConfig . sonarr !== null &&
257
265
Object . keys ( applicationConfig . sonarr ) . length <= 0
258
266
) {
259
- console . log ( `No sonarr instances defined.` ) ;
267
+ logger . info ( `No sonarr instances defined.` ) ;
260
268
}
261
269
270
+ logHeading ( `Processing Radarr ...` ) ;
271
+
262
272
for ( const instanceName in applicationConfig . radarr ) {
263
- console . log ( `Processing Radarr instance: ${ instanceName } ` ) ;
273
+ logger . info ( `Processing Radarr instance: ${ instanceName } ` ) ;
264
274
const instance = applicationConfig . radarr [ instanceName ] ;
265
275
await configureRadarrApi ( instance . base_url , instance . api_key ) ;
266
276
await pipeline ( instance , "RADARR" ) ;
@@ -273,7 +283,7 @@ const run = async () => {
273
283
applicationConfig . radarr !== null &&
274
284
Object . keys ( applicationConfig . radarr ) . length <= 0
275
285
) {
276
- console . log ( `No radarr instances defined.` ) ;
286
+ logger . info ( `No radarr instances defined.` ) ;
277
287
}
278
288
} ;
279
289
0 commit comments