1. 名前空間 `console^I
[`Exposed$=(Window,Worker,Worklet)] namespace `console@I { /* が、下の名前空間~obj要件も見よ。 ◎ but see namespace object requirements below */ // ~log用 void `assert$m(optional `boolean$ %condition = false, any... %data); void `clear$m(); void `debug$m(any... %data); void `error$m(any... %data); void `info$m(any... %data); void `log$m(any... %data); void `table$m(any %tabularData, optional sequence<`DOMString$> %properties); void `trace$m(any... %data); void `warn$m(any... %data); void `dir$m(any %item, optional `object$? %options); void `dirxml$m(any... %data); // 計数~用 void `count$m(optional `DOMString$ %label = "default"); void `countReset$m(optional `DOMString$ %label = "default"); // ~group分け void `group$m(any... %data); void `groupCollapsed$m(any... %data); void `groupEnd$m(); // 計時 void `time$m(optional `DOMString$ %label = "default"); void `timeLog$m(optional `DOMString$ %label = "default", any... %data); void `timeEnd$m(optional `DOMString$ %label = "default"); };
注記: 歴史的な理由から、 `console$I は小文字にされている。 ◎ For historical reasons, console is lowercased.
注記: 開発者~consoleが[ 開かれていない/存在しない ]場合でも、 `console$I は常に~scriptから可視, かつ利用-可能なことが重要である。 ◎ It is important that console is always visible and usable to scripts, even if the developer console has not been opened or does not exist.
歴史的な~web互換性の理由から、 `console$I 用の`名前空間~obj$の `Prototype^sl は, `ObjectPrototype$jI に代えて空~objで~MUST — `ObjectCreate$A( `ObjectPrototype$jI ) により作成されかのように。 ◎ For historical web-compatibility reasons, the namespace object for console must have as its [[Prototype]] an empty object, created as if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.
1.1. ~log用~method
1.1.1. `assert(condition, ...data)^m
- ~IF[ %condition ~EQ ~T ] ⇒ ~RET ◎ If condition is true, return.
- %~message ~LET 表明の失敗を指示するような, 汎用の, 整形~指定子を伴わない,文字列(例: `Assertion failed^l ) ◎ Let message be a string without any formatting specifiers indicating generically an assertion failure (such as "Assertion failed").
- ~IF[ %data は`空$である ] ⇒ %data に %~message を`付加する$ ◎ If data is empty, append message to data.
-
~ELSE: ◎ Otherwise:
- %先頭 ~LET %data[0] ◎ Let first be data[0].
- ~IF[ `Type$A( %先頭 ) ~NEQ `String^jT ] ⇒ %data に %~message を `前付加する$ ◎ If Type(first) is not String, then prepend message to data.
- ~ELSE ⇒ %data[0] ~SET 次を順に連結した結果 ⇒# %~message, `003A^U (:), `0020^U ~SPACE, %先頭 ◎ Otherwise: • Let concat be the concatenation of message, U+003A (:), U+0020 SPACE, and first. • Set data[0] to concat.
- `Logger$A( `assert^l, %data ) を遂行する ◎ Perform Logger("assert", data).
1.1.2. `clear()^m
- 適切な`~group~stack$を`空にする$ ◎ Empty the appropriate group stack.
- 環境にて可能なら,~consoleを~clearする(他の場合,何もしない) ◎ If possible for the environment, clear the console. (Otherwise, do nothing.)
1.1.3. `debug(...data)^m
- `Logger$A( `debug^l, %data ) を遂行する ◎ Perform Logger("debug", data).
1.1.4. `error(...data)^m
- `Logger$A( `error^l, %data ) を遂行する ◎ Perform Logger("error", data).
1.1.5. `info(...data)^m
- `Logger$A( `info^l, %data ) を遂行する ◎ Perform Logger("info", data).
1.1.6. `log(...data)^m
- `Logger$A( `log^l, %data ) を遂行する ◎ Perform Logger("log", data).
1.1.7. `table(tabularData, properties)^m
~tableを構築しようと試行した上で, %logLevel `log^l の下で~logする — ~tableの各列は %tabularData の各~propからなり(または %properties を利用する),各行は %tabularData からなる。 表構造として構文解析できなかった場合、単に引数を~logすることに~fall-backする。 ◎ Try to construct a table with the columns of the properties of tabularData (or use properties) and rows of tabularData and log it with a logLevel of "log". Fall back to just logging the argument if it can’t be parsed as tabular.
未策定 — これには良い~algoが必要になる。 ◎ TODO: This will need a good algorithm.
1.1.8. `trace(...data)^m
- %trace ~LET 実装に特有の, 何らかの, 対話的にもなり得る,[ この~methodを~callした所からの~callstack ]の表現 ◎ Let trace be some implementation-specific, potentially-interactive representation of the callstack from where this method was called.
- 任意選択で ⇒ %trace 用の~labelとして[ `Formatter$A( %data ) の結果 ]を組入れる ◎ Optionally, let formattedData be the result of Formatter(data), and incorporate formattedData as a label for trace.
- `Printer$A( `trace^l, « %trace » ) を遂行する ◎ Perform Printer("trace", « trace »).
注記: ~stack-trace内に~printされる関数の識別子は、実装に依存する。 それはまた, `new Error().stack^c 内に見られるものと同じ識別子になることは保証されない。 ◎ The identifier of a function printed in a stack trace is implementation-dependant. It is also not guaranteed to be the same identifier that would be seen in new Error().stack.
1.1.9. `warn(...data)^m
- `Logger$A( `warn^l, %data ) を遂行する ◎ Perform Logger("warn", data).
1.1.10. `dir(item, options)^m
- %object ~LET %item に`汎用~JS~obj整形$を適用した結果 ◎ Let object be item with generic JavaScript object formatting applied.
- `Printer$A( `dir^l, « %object », %options ) を遂行する ◎ Perform Printer("dir", « object », options).
1.1.11. `dirxml(...data)^m
- %finalList ~LET 新たな空`~list$ ◎ Let finalList be a new list, initially empty.
-
%data 内の~EACH( %item ) に対し: ◎ For each item of data:
- %変換-済み ~LET %item の~DOM木~表現が可能ならば それ / ~ELSE_ %item に`最適に有用な整形$を適用した結果 ◎ Let converted be a DOM tree representation of item if possible; otherwise let converted be item with optimally useful formatting applied.
- %finalList に %変換-済み を付加する ◎ Append converted to finalList.
- `Logger$A( `dirxml^l, %finalList ) を遂行する ◎ Perform Logger("dirxml", finalList).
1.2. 計数~用~method
各 `console$I 名前空間~objには、 `計数~map@ が結付けられる。 それは、各~entryが[ `文字列$→数 ]として与えられる`~map$であり,初期~時には空とする。 ◎ Each console namespace object has an associated count map, which is a map of strings to numbers, initially empty.
1.2.1. `count(label)^m
- %map ~LET 此れの`計数~map$ ◎ Let map be the associated count map.
- ~IF[ %map[ %label ] ~NEQ ε ] ⇒ %map[ %label ] ~INCBY 1 ◎ If map[label] exists, set map[label] to map[label] + 1.
- ~ELSE ⇒ %map[ %label ] ~SET 1 ◎ Otherwise, set map[label] to 1.
- %concat ~LET 次を順に連結した結果 ⇒# %label, `003A^U (:), `0020^U ~SPACE, `ToString$A( %map[ %label ]) ◎ Let concat be the concatenation of label, U+003A (:), U+0020 SPACE, and ToString(map[label]).
- `Logger$A( `count^l, « %concat ») を遂行する ◎ Perform Logger("count", « concat »).
1.2.2. `countReset(label)^m
- %map ~LET 此れの`計数~map$ ◎ Let map be the associated count map.
- ~IF[ %map[ %label ] ~NEQ ε ] ⇒ %map[ %label ] ~SET 0 ◎ If map[label] exists, set map[label] to 0.
-
~ELSE: ◎ Otherwise:
- %~message ~LET [ 所与の~labelに計数が結付けられてないこと ]を指示するような, 汎用の, 整形~指定子を伴わない,文字列 ◎ Let message be a string without any formatting specifiers indicating generically that the given label does not have an associated count.
- `Logger$A( `countReset^l, « %message » ) を遂行する ◎ Perform Logger("countReset", « message »);
1.3. ~group分け~method
`~group@ は、実装に特有の, 対話的にもなり得る, 親より字下げ~levelが 1 つ深い, 出力~用の~viewであり、 `Printer$A の~callにより生産される。 各 `console$I 名前空間~objには、 `~group~stack@ が結付けられる — それは、`~stack$であり,初期~時には空とする。 `~group~stack$内の最後の`~group$のみが `Printer$A の~callにより生産される出力を~hostすることになる。 ◎ A group is an implementation-specific, potentially-interactive view for output produced by calls to Printer, with one further level of indentation than its parent. Each console namespace object has an associated group stack, which is a stack, initially empty. Only the last group in a group stack will host output produced by calls to Printer.
1.3.1. `group(...data)^m
- %~group ~LET 新たな`~group$ ◎ Let group be a new group.
- %~group~label ~LET [ %data は`空$でないならば `Formatter$A( %data ) の結果 / ~ELSE_ 実装により選ばれる[ `~group$を表現する~label ]] ◎ If data is not empty, let groupLabel be the result of Formatter(data). Otherwise, let groupLabel be an implementation-chosen label representing a group.
- %~group~label を %~group 用の~labelとして組入れる ◎ Incorporate groupLabel as a label for group.
- 任意選択で ⇒ ~IF[ 環境は対話的~groupを~supportする ] ⇒ %~group は既定で展開されるべきである ◎ Optionally, if the environment supports interactive groups, group should be expanded by default.
- `Printer$A( `group^l, « %~group ») を遂行する ◎ Perform Printer("group", « group »).
- 適切な`~group~stack$に %~group を`~push$する ◎ Push group onto the appropriate group stack.
1.3.2. `groupCollapsed(...data)^m
- %~group ~LET 新たな`~group$ ◎ Let group be a new group.
- %~group~label ~LET [ %data は空でないならば `Formatter$A( %data ) の結果 / ~ELSE_ 実装により選ばれる[ `~group$を表現する~label ]] ◎ If data is not empty, let groupLabel be the result of Formatter(data). Otherwise, let groupLabel be an implementation-chosen label representing a group.
- %~group~label を %~group 用の~labelとして組入れる ◎ Incorporate groupLabel as a label for group.
- 任意選択で ⇒ ~IF[ 環境は対話的~groupを~supportする ] ⇒ %~group は既定で畳まれるべきである ◎ Optionally, if the environment supports interactive groups, group should be collapsed by default.
- `Printer$A( `groupCollapsed^l, « %~group ») を遂行する ◎ Perform Printer("groupCollapsed", « group »).
- 適切な`~group~stack$に %~group を`~push$する ◎ Push group onto the appropriate group stack.
1.3.3. `groupEnd()^m
- `~group~stack$から`~pop$する ◎ Pop the last group from the group stack.
1.4. 計時~method
各 `console$I 名前空間~objには `~timer~table@ が結付けられる。 それは、各~entryが[ `文字列$→時刻 ]として与えられる`~map$であり,初期~時には空とする。 ◎ Each console namespace object has an associated timer table, which is a map of strings to times, initially empty.
1.4.1. `time(label)^m
- %~timer~table ~LET 此れの`~timer~table$ ◎ ↓
-
~IF[ %~timer~table[ %label ] ~NEQ ε ]:
- 任意選択で ⇒ [ ~label %label を伴う~timerは,すでに開始されている ]ことを指示する警告を,~consoleに報告する
- ~RET
- ~ELSE ⇒ %~timer~table[ %label ] ~SET 現在の時刻 ◎ Otherwise, set the value of the entry with key label in the associated timer table to the current time.
1.4.2. `timeLog(label, ...data)^m
- %~timer~table ~LET 此れの`~timer~table$ ◎ Let timerTable be the associated timer table.
- %開始-時刻 ~LET %~timer~table[ %label ] ◎ Let startTime be timerTable[label].
-
%時間長 ~LET 実装~定義な書式で ( 現在の時刻 ~MINUS %開始-時刻 ) を表現している文字列 ◎ Let duration be a string representing the difference between the current time and startTime, in an implementation-defined format.
`4650^l, `4650.69 ms^l, `5 seconds^l, `00:05^l は、どれも 4650.69 ミリ秒間を表示する 適度な仕方である。 ◎ "4650", "4650.69 ms", "5 seconds", and "00:05" are all reasonable ways of displaying a 4650.69 ms duration.
- %concat ~LET 次を順に連結した結果 ⇒# %label, `003A^U (:), `0020^U ~SPACE, %時間長 ◎ Let concat be the concatenation of label, U+003A (:), U+0020 SPACE, and duration.
- %data に %concat を`前付加する$ ◎ Prepend concat to data.
- `Printer$A( `timeLog^l, %data ) を遂行する ◎ Perform Printer("timeLog", data).
利用者が,何らかの余分の~dataを伴う中間的な~timer~logを給し易くするため、~timerが存続する限り, `timeLog()$m の~callに渡す %data ~parameterは `Logger$A の~callに含まれる。 例えば: ◎ The data parameter in calls to timeLog() is included in the call to Logger to make it easier for users to supply intermediate timer logs with some extra data throughout the life of a timer. For example:
console.time("MyTimer"); console.timeLog("MyTimer", "Starting application up…"); /* おそらく,複雑な~appを~bootstrapするような 何らかの~codeが走る ◎ Perhaps some code runs to bootstrap a complex app */ // ... console.timeLog("MyTimer", "UI is setup, making API calls now"); /* おそらく,~appの~dataを埋めるような 何らかの `fetch()^c をここで行う ◎ Perhaps some fetch()'s here filling the app with data */ // ... console.timeEnd("MyTimer");
1.4.3. `timeEnd(label)^m
- %~timer~table ~LET 此れの`~timer~table$ ◎ Let timerTable be the associated timer table.
- %開始-時刻 ~LET %~timer~table[ %label ] ◎ Let startTime be timerTable[label].
- %~timer~table[ %label ] ~SET ε ◎ Remove timerTable[label].
- %時間長 ~LET 実装~定義な書式で ( 現在の時刻 ~MINUS %開始-時刻 ) を表現している文字列 ◎ Let duration be a string representing the difference between the current time and startTime, in an implementation-defined format.
- %concat ~LET 次を順に連結した結果 ⇒# %label, `003A^U (:), `0020^U ~SPACE, %時間長 ◎ Let concat be the concatenation of label, U+003A (:), U+0020 SPACE, and duration.
- `Printer$A( `timeEnd^l, « %concat » ) を遂行する ◎ Perform Printer("timeEnd", « concat »).
%~timer~table 内に所与の %label が存在しないときに, `timeEnd()$m, `timeLog()$m が公式的に警告を~consoleに報告させる計画については whatwg/console#134 を見よ。 ◎ See whatwg/console#134 for plans to make timeEnd() and timeLog() formally report warnings to the console when a given label does not exist in the associated timer table.
2. 抽象~演算の~support法
2.1. `Logger^A(%logLevel, %args)
`Logger^A 演算は、~log~levelおよび,他の引数からなる`~list$を受容する。 その主な出力を成すのは、実装により定義される,結果を~consoleへ~printする副作用である。 この仕様は、そうする間に整形-指定子をどう処理するかについて述べる。 ◎ The logger operation accepts a log level and a list of other arguments. Its main output is the implementation-defined side effect of printing the result to the console. This specification describes how it processes format specifiers while doing so.
- ~IF[ %args は`空$である ] ⇒ ~RET ◎ If args is empty, return.
- %first ~LET %args[0] ◎ Let first be args[0].
- %rest ~LET %args 内の %first に後続するすべての要素からなる`~list$ ◎ Let rest be all elements following first in args.
- ~IF[ %rest は`空$である ] ⇒# `Printer$A( %logLevel, « %first ») を遂行する; ~RET ◎ If rest is empty, perform Printer(logLevel, « first ») and return.
- ~IF[ %first は整形-指定子を包含しない ] ⇒ `Printer$A( %logLevel, %args ) を遂行する ◎ If first does not contain any format specifiers, perform Printer(logLevel, args).
- ~ELSE ⇒ `Printer$A( %logLevel, `Formatter$A( %args )) を遂行する ◎ Otherwise, perform Printer(logLevel, Formatter(args)).
- ~RET `undefined^jv 【 ~RET と ~RET `undefined^jv の違いは?】 ◎ Return undefined.
注記: ~algoが返る前に~printされることが重要である。 多くの開発者~consoleは、その中に手入力した最後の演算の結果を~printする。 そのような~consoleにおいては、開発者が `console.log("hello!")^c と手入力したとき,先ず `hello!^l, 次に `console.log^c ~callの返り値 `undefined^jv を~printすることになる。 ◎ It’s important that the printing occurs before returning from the algorithm. Many developer consoles print the result of the last operation entered into them. In such consoles, when a developer enters console.log("hello!"), this will first print "hello!", then the undefined return value from the console.log call.
2.2. `Formatter^A(%args)
`Formatter^A 演算は、供された最初の引数を,後続の引数を用いて整形しようと試行する。 それは、最初の引数~内の整形~指定子が尽きるか, 他の引数が尽きるまで,入力を整形しようと試行した上で、~print用に相応しい何個かの~objからなる`~list$を返す: ◎ The formatter operation tries to format the first argument provided, using the other arguments. It will try to format the input until no formatting specifiers are left in the first argument, or no more arguments are left. It returns a list of objects suitable for printing.
- %target ~LET %args の最初の要素 ◎ Let target be the first element of args.
- %current ~LET %args の 2 個目の要素 ◎ Let current be the second element of args.
-
%指定子 ~LET %target 内の未処理の整形-指定子のうち,最初に現れるもの ◎ Find the first possible format specifier specifier, from the left to the right in target.
【 整形-指定子がない場合や %args が 1 個の要素のみからなる場合にどうなるか定義されていない。 この~algoの末尾にある検査は、先頭に移動されるべき? 】【 “未処理の” はこの訳による追加。 さもなければ、同じ整形-指定子を何度も繰り返すことにもなり得るので。 】
-
%変換-済み ~LET %指定子 に応じて,次で与えられる値:
- `%s^l
- `Call$A( `String$jI, `undefined^jv, « %current » ) ◎ If specifier is %s, let converted be the result of Call(%String%, undefined, « current »).
- `%d^l
- `%i^l
- `Type$A( %current ) に応じて ⇒# `Symbol^jT ならば `NaN^jv / ~ELSE_ `Call$A( `parseInt$jI, `undefined^jv, « %current, 10 » ) ◎ If specifier is %d or %i: • If Type(current) is Symbol, let converted be NaN • Otherwise, let converted be the result of Call(%parseInt%, undefined, « current, 10 »).
- `%f^l
- `Type$A( %current ) に応じて ⇒# `Symbol^jT ならば `NaN^jv / ~ELSE_ `Call$A( `parseFloat$jI, `undefined^jv, « %current » ) ◎ If specifier is %f: • If Type(current) is Symbol, let converted be NaN • Otherwise, let converted be the result of Call(%parseFloat%, undefined, « current »).
- `%o^l
- 任意選択で、 %指定子 または ⇒ %current に`最適に有用な整形$を適用した結果 ◎ If specifier is %o, optionally let converted be current with optimally useful formatting applied.
- `%O^l
- 任意選択で、 %指定子 または ⇒ %current に`汎用~JS~obj整形$を適用した結果 ◎ If specifier is %O, optionally let converted be current with generic JavaScript object formatting applied.
- `%c^l
- (未策定) ◎ TODO: process %c
- %target 内の %指定子 を %変換-済み に置換する 【 %変換-済み 内にも整形-指定子があった場合、その指定子も “未処理” と見なされるのか?】 ◎ If any of the previous steps set converted, replace specifier in target with converted.
- %結果 ~LET %target, および %args 内の 3 個目~以降の要素からなる`~list$ ◎ Let result be a list containing target together with the elements of args starting from the third onward.
-
- ~IF[ %target 内に未処理の整形-指定子はない ] ⇒ ~RET %結果 ◎ If target does not have any format specifiers left, return result.
- ~IF[ %結果 の`~size$ ~EQ 1 ] ⇒ ~RET %結果 ◎ If result’s size is 1, return result.
- ~RET `Formatter$A( %結果 ) ◎ Return Formatter(result).
2.2.1. 各種 整形~指定子の要約
上の~algoにて処理される整形-指定子たちを,以下に要約する(参考) — 表~内の “要素” は、指定子を代用する要素を指すとする: ◎ The following is an informative summary of the format specifiers processed by the above algorithm.
指定子 | 目的 | 型~変換 |
---|---|---|
`%s^l | 要素は 文字列に変換される ◎ Element which substitutes is converted to a string | `String$jI(%element) |
`%d^l / `%i^l | 要素は 整数に変換される ◎ Element which substitutes is converted to an integer | `parseInt$jI(%element, 10) |
`%f^l | 要素は 浮動小数点数に変換される ◎ Element which substitutes is converted to a float | `parseFloat$jI(%element, 10) |
`%o^l | 要素は `最適に有用な整形$で表示される ◎ Element is displayed with optimally useful formatting | n/a |
`%O^l | 要素は `汎用~JS~obj整形$で表示される ◎ Element is displayed with generic JavaScript object formatting | n/a |
`%c^l | 供される~CSSを要素に適用する ◎ Applies provided CSS | n/a |
2.3. `Printer^A(%logLevel, %args[, %options])
`Printer^A 演算は、実装により定義され,[ 厳しさを指示する~log~level, ~printする何個かの引数からなる~List, 実装に特有の整形~optionを与える~obj(省略可) ]を受容する。 %args 内に現れる要素は、次のうちいずれかになる: ◎ The printer operation is implementation-defined. It accepts a log level indicating severity, a List of arguments to print, and an optional object of implementation-specific formatting options. Elements appearing in args will be one of the following:
- ~JS~obj — 型は問わず ◎ JavaScript objects of any type.
- ~stack-traceや`~group$など,~printできるものを成すような、実装に特有の表現 ◎ Implementation-specific representations of printable things such as a stack trace or group.
- `汎用~JS~obj整形$を適用した結果の~obj ◎ Objects with either generic JavaScript object formatting\
- `最適に有用な整形$を適用した結果の~obj ◎ or optimally useful formatting applied.
%options ~objが渡され, かつ[ `undefined^jv / `null^jv ]でない場合、実装は, %args 内の各 要素に 自身に特有の整形を適用するときに %options を利用して~MAY。 ◎ If the options object is passed, and is not undefined or null, implementations may use options to apply implementation-specific formatting to the elements in args.
実装が %args をどう~printするかは,実装に委ねられるが、実装は, 開発者の期待に沿うよう,~objを~spaceかそれに類する何かで区切るべきである。 ◎ How the implementation prints args is up to the implementation, but implementations should separate the objects by a space or something similar, as that has become a developer expectation.
`Printer^A 演算が~callされる時点では、すべての整形-指定子は織り込み済みであり,[ 整形-指定子により消費されるものと意味された,引数 ]は %args 内に残されないことになる。 実装の仕事は、単純に~Listを~printすることである。 `Printer^A の~callにより生産される出力が現れるのは、適切な`~group~stack$が空でなければ その最後の`~group$の中に限られ,他の場合は~console内の他所になるべきである。 ◎ By the time the printer operation is called, all format specifiers will have been taken into account, and any arguments that are meant to be consumed by format specifiers will not be present in args. The implementation’s job is simply to print the List. The output produced by calls to Printer should appear only within the last group on the appropriate group stack if the group stack is not empty, or elsewhere in the console otherwise.
`Printer^A 演算の~call時に,~consoleが開かれていない場合、実装は ~messageを~bufferするべきである(概して,少なくとも何 100 個かは) — それらを,実装により選ばれる上限までの未来に示すため。 ◎ If the console is not open when the printer operation is called, implementations should buffer messages to show them in the future up to an implementation-chosen limit (typically on the order of at least 100).
2.3.1. ~logの厳しさ~levelの指示-法
`console$I の各~methodは、それぞれに一意な値を[ `Printer^A の~call時の %logLevel ~parameter ]に利用する — 実装は、各~methodごとに,~printする~messageを~custom化できるようになる。 しかしながら、一連の~methodを 次の表に要約される 4 ~groupに分けて,同じ~groupに属する出力は同様に扱うことも、共通的に実施されている: ◎ Each console method uses a unique value for the logLevel parameter when calling Printer, allowing implementations to customize each printed message depending on the method from which it originated. However, it is common practice to group together certain methods and treat their output similarly, in four broad categories. This table summarizes these common groupings:
~group◎ Grouping | `console$I ~method | 概要◎ Description |
---|---|---|
log | `log()$m, `trace()$m, `dir()$m, `dirxml()$m, `group()$m, `groupCollapsed()$m, `debug()$m, `timeLog()$m | 汎用の~log ◎ A generic log |
info | `count()$m, `info()$m, `timeEnd()$m | 参考の~log ◎ An informative log |
warn | `warn()$m, `countReset()$m | ~messageにより指示される何かを利用者~向けに警告する ~log ◎ A log warning the user of something indicated by the message |
error | `error()$m, `assert()$m | 利用者~向けに~errorを指示する~log ◎ A log indicating an error to the user |
この~group分けに意味されるのは,共通的な実施を文書~化することであり、実装が,各~method用に特別な挙動 — 次の例に見られるような — を供さないよう拘束することではない: ◎ These groupings are meant to document common practices, and do not constrain implementations from providing special behavior for each method, as in the following examples:
ここに見られる ある実装は、 `timeEnd()$m への~callにより生産される出力を青くすることにした — `info()$m による出力は より中立的な色のままにしつつ。 ◎ Here you can see one implementation chose to make output produced by calls to timeEnd() blue, while leaving info() a more neutral color.
`count()$m の~callは、常に,新たな出力を~printするとは限らず,以前に出力した計数を更新することもある。 ◎ Calls to count() might not always print new output, but instead could update previously-output counts.
2.3.2. `Printer^A ~UX新機軸
`Printer$A は実装により定義されるので、その実装には,~UX(利用者~体験)における新機軸も共通的に見られる。 ~UXの増補として,例えば次のものが挙げられるが、これらに限られない: ◎ Since Printer is implementation-defined, it is common to see UX innovations in its implementations. The following is a non-exhaustive list of potential UX enhancements:
-
~spamを防止するため、互いに一致する出力は一つに集約する。 ◎ De-duplication of identical output to prevent spam.
この例の実装は、互いに一致する複数の~messageを一括するのみならず,何個の~messageが一緒に一括されたかも供する。 ◎ In this example, the implementation not only batches multiple identical messages, but also provides the number of messages that have been batched together.
-
利用者が ~messageを~logの厳しさ~levelで絞込めるようにするための、脇に置かれる余分の~UI。 ◎ Extra UI off to the side allowing the user to filter messages by log level severity.
- `~timer~table$, `~group~stack$, その他の内部に保守される~dataの現在の状態を指示するような、脇に置かれる余分の~UI。 ◎ Extra UI off to the side indicating the current state of the timer table, group stack, or other internally maintained data.
- ~consoleのある部位を明滅して,利用者に何か重要なことを~alertする。 ◎ Flashing portions of the console to alert the user of something important.
2.3.3. 共通的な~obj整形-
~objは概して、その文脈に相応しく整形されて~printされることになる。 この節では、~objがその文脈にて最も有用に整形されるような,共通的な仕方を述べる。 この節に述べる整形は、[ 最終的に `Printer$A に渡されることになる,実装に特有の~obj表現 ]に適用されることに注意。 整形による実際の副作用は,そこで見えることになる。 ◎ Typically objects will be printed in a format that is suitable for their context. This section describes common ways in which objects are formatted to be most useful in their context. It should be noted that the formatting described in this section is applied to implementation-specific object representations that will eventually be passed into Printer, where the actual side effect of formatting will be seen.
`汎用~JS~obj整形@ を伴う~objは、展開-可能にもなり得る,汎用~JS~objの表現である。 `最適に有用な整形@ を伴う~objは、最大に有用かつ参考と判定された~objの,対話的にもなり得る, 実装に特有の表現である。 ◎ An object with generic JavaScript object formatting is a potentially expandable representation of a generic JavaScript object. An object with optimally useful formatting is an implementation-specific, potentially-interactive representation of an object judged to be maximally useful and informative.
2.3.4. 例: Node.js における `Printer^A
Node.js ~platform上で `Printer^A 演算を実装する最も単純な仕方は、それまでに整形された引数たちを~spaceで区切って連結した結果の出力を `stdout^c / `stderr^c に書込むことである。 ◎ The simplest way to implement the printer operation on the Node.js platform is to join the previously formatted arguments separated by a space and write the output to stdout or stderr.
`ECMASCRIPT$r を用いる Node.js における実装~例: ◎ Example implementation in Node.js using [ECMASCRIPT]:
const %util = require('util'); function print(%logLevel, ...%args) { const %message = %util.format(...%args); if (%logLevel === 'error') { process.stderr.write(%message + '\n'); } else if (%logLevel === 'log' || %logLevel === 'info' || %logLevel === 'warn') { process.stdout.write(%message + '\n'); } }
ここでの `util.format^c 関数により たくさんの作業が行われる。 それは、入子の~objを文字列化して,文字列でない引数は読める文字列~versionに変換する。 例えば `undefined^jv は 文字列 `undefined^l に, `false^jv は `false^l になる: ◎ Here a lot of the work is done by the util.format function. It stringifies nested objects, and converts non-string arguments into a readable string version, e.g. undefined becomes the string "undefined" and false becomes "false":
print('log', 'duck', [{foo: 'bar'}]); // prints: `duck [ { foo: 'bar' } ]\n^c on stdout print('log', 'duck', false); // prints: `duck false\n^c on stdout print('log', 'duck', undefined); // prints: `duck undefined\n^c on stdout