11.12.2. TypeScript 컨텍스트 오브젝트 참조

context 오브젝트에는 함수 개발자가 액세스할 수 있는 여러 속성이 있습니다. 이러한 속성에 액세스하면 들어오는 HTTP 요청에 대한 정보를 제공하고 클러스터 로그에 출력을 쓸 수 있습니다.

11.12.2.1. log

클러스터 로그에 출력을 작성하는 데 사용할 수 있는 로깅 오브젝트를 제공합니다. 로그는 Pino 로깅 API를 따릅니다.

로그 예

export function handle(context: Context): string {
    // log the incoming request body's 'hello' parameter
    if (context.body) {
      context.log.info((context.body as Record<string, string>).hello);
    } else {
      context.log.info('No data received');
    }
    return 'OK';
}

kn func invoke 명령을 사용하여 함수에 액세스할 수 있습니다.

명령 예

$ kn func invoke --target 'http://example.function.com'

출력 예

{"level":30,"time":1604511655265,"pid":3430203,"hostname":"localhost.localdomain","reqId":1,"msg":"Processing customer"}

로그 수준을 fatal,error,warn,info,debug,trace 또는 silent 중 하나로 변경할 수 있습니다. 이렇게 하려면 config 명령을 사용하여 해당 값 중 하나를 환경 변수 FujiNC _LOG_LEVEL에 할당하여 logLevel 값을 변경합니다.