feat(config): stream type for bunyan config
This commit is contained in:
parent
deee5c0cbd
commit
24f91aa1b4
|
@ -0,0 +1,5 @@
|
|||
data:
|
||||
logger:
|
||||
level: debug
|
||||
name: salty-dog
|
||||
stream: !stream stderr
|
|
@ -7,6 +7,7 @@ import { promisify } from 'util';
|
|||
import { envType } from 'src/config/type/Env';
|
||||
import { includeSchema, includeType } from 'src/config/type/Include';
|
||||
import { regexpType } from 'src/config/type/Regexp';
|
||||
import { streamType } from 'src/config/type/Stream';
|
||||
import { NotFoundError } from 'src/error/NotFoundError';
|
||||
|
||||
export const CONFIG_ENV = 'SALTY_HOME';
|
||||
|
@ -14,6 +15,7 @@ export const CONFIG_SCHEMA = Schema.create([DEFAULT_SAFE_SCHEMA], [
|
|||
envType,
|
||||
includeType,
|
||||
regexpType,
|
||||
streamType,
|
||||
]);
|
||||
|
||||
includeSchema.schema = CONFIG_SCHEMA;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import { Type as YamlType } from 'js-yaml';
|
||||
|
||||
import { NotFoundError } from 'src/error/NotFoundError';
|
||||
|
||||
const ALLOWED_STREAMS = new Set([
|
||||
'stdout',
|
||||
'stderr',
|
||||
]);
|
||||
|
||||
export const streamType = new YamlType('!stream', {
|
||||
kind: 'scalar',
|
||||
resolve(name: string) {
|
||||
if (ALLOWED_STREAMS.has(name) && Reflect.has(process, name)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new NotFoundError(`process stream not found: ${name}`);
|
||||
}
|
||||
},
|
||||
construct(name: string) {
|
||||
return Reflect.get(process, name);
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue