Class console
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
콘솔
이 클래스를 사용하면 개발자가 스크립트가 표준 Cloud 프로젝트와 연결된 경우 실행 로그 및 Google Cloud Logging에 쓸 수 있습니다.
Cloud Logging 및 구조화된 로깅을 완전히 지원하려면 Logger
를 사용하세요. console
메서드는 객체를 문자열로 직렬화하며 구조화된 로깅 LogEntry
의 일부로 jsonPayload
를 지원하지 않습니다.
function measuringExecutionTime() {
const label = "myFunction() time"; // Labels the timing log entry.
console.time(label); // Starts the timer.
try {
myFunction(); // Function to time.
} catch (e) {
// Logs an ERROR message.
console.error("myFunction() yielded an error: " + e);
}
console.timeEnd(label); // Stops the timer, logs execution duration.
}
function myFunction() {
// ...
}
자세한 문서
error()
Stackdriver Logging에 빈 ERROR 수준 메시지를 출력합니다.
Stackdriver Logging에 ERROR 수준 메시지를 출력합니다.
매개변수
이름 | 유형 | 설명 |
formatOrObject | Object | 대체 문자열을 0개 이상 포함하는 문자열 또는 다른 매개변수가 없는 경우 JavaScript 객체로 로깅할 JavaScript 객체입니다. |
values | Object... | 메시지 내에서 대체 문자열을 바꾸는 객체입니다. 이렇게 하면 출력 형식을 추가로 제어할 수 있습니다. |
info()
Stackdriver Logging에 빈 INFO 수준 메시지를 출력합니다.
Stackdriver Logging에 INFO 수준 메시지를 출력합니다.
매개변수
이름 | 유형 | 설명 |
formatOrObject | Object | 대체 문자열을 0개 이상 포함하는 문자열 또는 다른 매개변수가 없는 경우 JavaScript 객체로 로깅할 JavaScript 객체입니다. |
values | Object... | 메시지 내에서 대체 문자열을 바꾸는 객체입니다. 이렇게 하면 출력 형식을 추가로 제어할 수 있습니다. |
log()
Stackdriver Logging에 빈 DEBUG 수준 메시지를 출력합니다.
Stackdriver Logging에 DEBUG 수준 메시지를 출력합니다.
매개변수
이름 | 유형 | 설명 |
formatOrObject | Object | 대체 문자열을 0개 이상 포함하는 문자열 또는 다른 매개변수가 없는 경우 JavaScript 객체로 로깅할 JavaScript 객체입니다. |
values | Object... | 메시지 내에서 대체 문자열을 바꾸는 객체입니다. 이렇게 하면 출력 형식을 추가로 제어할 수 있습니다. |
time(label)
작업에 걸리는 시간을 추적하는 데 사용할 수 있는 타이머를 시작합니다.
매개변수
이름 | 유형 | 설명 |
label | String | 새 타이머에 지정할 이름입니다. |
timeEnd(label)
이전에 console.time()
를 호출하여 시작한 타이머를 중지합니다. 시간은 Stackdriver에 로깅됩니다.
매개변수
이름 | 유형 | 설명 |
label | String | 중지할 타이머의 이름입니다. |
warn()
Stackdriver Logging에 빈 WARNING 수준 메시지를 출력합니다.
Stackdriver Logging에 WARNING 수준 메시지를 출력합니다.
매개변수
이름 | 유형 | 설명 |
formatOrObject | Object | 대체 문자열을 0개 이상 포함하는 문자열 또는 다른 매개변수가 없는 경우 JavaScript 객체로 로깅할 JavaScript 객체입니다. |
values | Object... | 메시지 내에서 대체 문자열을 바꾸는 객체입니다. 이렇게 하면 출력 형식을 추가로 제어할 수 있습니다. |
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eThe \u003ccode\u003econsole\u003c/code\u003e class enables developers to write logs to Google Cloud's Stackdriver Logging service with various severity levels (DEBUG, INFO, ERROR, WARNING).\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods like \u003ccode\u003econsole.log()\u003c/code\u003e, \u003ccode\u003econsole.info()\u003c/code\u003e, \u003ccode\u003econsole.error()\u003c/code\u003e, and \u003ccode\u003econsole.warn()\u003c/code\u003e for logging messages with different severity.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use \u003ccode\u003econsole.time()\u003c/code\u003e and \u003ccode\u003econsole.timeEnd()\u003c/code\u003e to measure the execution time of specific code blocks.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003econsole\u003c/code\u003e methods accept format strings and values for structured logging, allowing objects and other data types to be included in log entries.\u003c/p\u003e\n"],["\u003cp\u003eLog entries can be viewed and analyzed in the Stackdriver Logging interface for debugging and monitoring purposes.\u003c/p\u003e\n"]]],[],null,["# Class console\n\nconsole\n\nThis class allows the developer to write to the Execution log and to [Google Cloud Logging](https://cloud.google.com/logging) if the script is associated with\na [standard\nCloud Project](https://developers.google.com/apps-script/guides/cloud-platform-projects#standard).\n\nFor full support of Cloud Logging and structured logging, use [Logger](/apps-script/reference/base/logger). The `console` methods\nserialize the objects to strings and do not support `json``Payload` as part of the structured\nlogging [`Log``Entry`](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry).\n\n```javascript\nfunction measuringExecutionTime() {\n const label = \"myFunction() time\"; // Labels the timing log entry.\n console.time(label); // Starts the timer.\n try {\n myFunction(); // Function to time.\n } catch (e) {\n // Logs an ERROR message.\n console.error(\"myFunction() yielded an error: \" + e);\n }\n console.timeEnd(label); // Stops the timer, logs execution duration.\n}\n\nfunction myFunction() {\n // ...\n}\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------------|-------------|------------------------------------------------------------------------|\n| [error()](#error()) | `void` | Outputs a blank ERROR level message to Stackdriver Logging. |\n| [error(formatOrObject, values)](#error(Object,Object...)) | `void` | Outputs an ERROR level message to Stackdriver Logging. |\n| [info()](#info()) | `void` | Outputs blank INFO level message to Stackdriver Logging. |\n| [info(formatOrObject, values)](#info(Object,Object...)) | `void` | Outputs an INFO level message to Stackdriver Logging. |\n| [log()](#log()) | `void` | Outputs a blank DEBUG level message to Stackdriver Logging. |\n| [log(formatOrObject, values)](#log(Object,Object...)) | `void` | Outputs a DEBUG level message to Stackdriver Logging. |\n| [time(label)](#time(String)) | `void` | Starts a timer you can use to track how long an operation takes. |\n| [timeEnd(label)](#timeEnd(String)) | `void` | Stops a timer that was previously started by calling `console.time()`. |\n| [warn()](#warn()) | `void` | Outputs a blank WARNING level message to Stackdriver Logging. |\n| [warn(formatOrObject, values)](#warn(Object,Object...)) | `void` | Outputs a WARNING level message to Stackdriver Logging. |\n\nDetailed documentation\n----------------------\n\n### `error()`\n\nOutputs a blank ERROR level message to Stackdriver Logging.\n\n*** ** * ** ***\n\n### `error(formatOrObject, values)`\n\nOutputs an ERROR level message to Stackdriver Logging.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------------------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| `format``Or``Object` | `Object` | a string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters. |\n| `values` | `Object...` | objects with which to replace substitution strings within the message. This gives you additional control over the format of the output. |\n\n*** ** * ** ***\n\n### `info()`\n\nOutputs blank INFO level message to Stackdriver Logging.\n\n*** ** * ** ***\n\n### `info(formatOrObject, values)`\n\nOutputs an INFO level message to Stackdriver Logging.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------------------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| `format``Or``Object` | `Object` | a string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters. |\n| `values` | `Object...` | objects with which to replace substitution strings within the message. This gives you additional control over the format of the output. |\n\n*** ** * ** ***\n\n### `log()`\n\nOutputs a blank DEBUG level message to Stackdriver Logging.\n\n*** ** * ** ***\n\n### `log(formatOrObject, values)`\n\nOutputs a DEBUG level message to Stackdriver Logging.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------------------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| `format``Or``Object` | `Object` | a string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters. |\n| `values` | `Object...` | objects with which to replace substitution strings within the message. This gives you additional control over the format of the output. |\n\n*** ** * ** ***\n\n### `time(label)`\n\nStarts a timer you can use to track how long an operation takes.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|---------------------------------|\n| `label` | `String` | The name to give the new timer. |\n\n*** ** * ** ***\n\n### `time``End(label)`\n\nStops a timer that was previously started by calling `console.time()`. The time duration\nis logged in Stackdriver.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|--------------------------------|\n| `label` | `String` | the name of the timer to stop. |\n\n*** ** * ** ***\n\n### `warn()`\n\nOutputs a blank WARNING level message to Stackdriver Logging.\n\n*** ** * ** ***\n\n### `warn(formatOrObject, values)`\n\nOutputs a WARNING level message to Stackdriver Logging.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------------------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| `format``Or``Object` | `Object` | a string containing zero or more substitution strings, or a JavaScript object to be logged as a JavaScript object if no other parameters. |\n| `values` | `Object...` | objects with which to replace substitution strings within the message. This gives you additional control over the format of the output. |"]]