@@ -2,10 +2,12 @@ import { randomBytes } from 'crypto';
2
2
import convict , { Schema , Config , SchemaObj } from 'convict' ;
3
3
import secp256k1 from 'secp256k1' ;
4
4
import { v4 as uuidV4 } from 'uuid' ;
5
+ import { LoggerProvider , Logger } from '@hyperledger-labs/bif-common' ;
5
6
6
7
export interface IBifApiServerOptions {
7
8
configFile : string ;
8
9
bifNodeId : string ;
10
+ logLevel : string ;
9
11
cockpitHost : string ;
10
12
cockpitPort : number ;
11
13
cockpitWwwRoot : string ;
@@ -64,6 +66,14 @@ export class ConfigService {
64
66
env : 'BIF_NODE_ID' ,
65
67
arg : 'bif-node-id' ,
66
68
} ,
69
+ logLevel : {
70
+ doc : 'The level at which loggers should be configured. Supported values include the following: ' +
71
+ 'error, warn, info, debug, trace' ,
72
+ format : ConfigService . formatNonBlankString ,
73
+ default : 'warn' ,
74
+ env : 'LOG_LEVEL' ,
75
+ arg : 'log-level' ,
76
+ } ,
67
77
cockpitHost : {
68
78
doc : 'The host to bind the Cockpit webserver to. Secure default is: 127.0.0.1. Use 0.0.0.0 to bind for any host.' ,
69
79
format : 'ipaddress' ,
@@ -83,7 +93,7 @@ export class ConfigService {
83
93
format : '*' ,
84
94
env : 'COCKPIT_WWW_ROOT' ,
85
95
arg : 'cockpit-www-root' ,
86
- default : 'node_modules/@hyperledger-labs/bif-cockpit/www/' ,
96
+ default : 'packages/bif-cmd-api-server/ node_modules/@hyperledger-labs/bif-cockpit/www/' ,
87
97
} ,
88
98
apiHost : {
89
99
doc : 'The host to bind the API to. Secure default is: 127.0.0.1. Use 0.0.0.0 to bind for any host.' ,
@@ -200,6 +210,7 @@ export class ConfigService {
200
210
return {
201
211
configFile : '.config.json' ,
202
212
bifNodeId : uuidV4 ( ) ,
213
+ logLevel : 'debug' ,
203
214
publicKey,
204
215
privateKey,
205
216
apiCorsDomainCsv : ( schema . apiCorsDomainCsv as SchemaObj ) . default ,
@@ -227,6 +238,9 @@ export class ConfigService {
227
238
}
228
239
ConfigService . config . validate ( ) ;
229
240
this . validateKeyPairMatch ( ) ;
241
+ const level = ConfigService . config . get ( 'logLevel' ) ;
242
+ const logger : Logger = LoggerProvider . getOrCreate ( { label : 'config-service' , level } ) ;
243
+ logger . info ( 'Configuration validation OK.' ) ;
230
244
}
231
245
return ConfigService . config ;
232
246
}
0 commit comments