•  


google-cloud-go/logging at main · googleapis/google-cloud-go · GitHub
Skip to content

Latest commit

 

History

History

logging

Cloud Logging Go Reference

For an interactive tutorial on using the client library in a Go application, click Guide Me .

Example Usage

First create a logging.Client to use throughout your application: [snip]:# (logging-1)

ctx
 :=
 context
.
Background
()
client
, 
err
 :=
 logging
.
NewClient
(
ctx
, 
"my-project"
)
if
 err
 !=
 nil
 {
   
// TODO: Handle error.

}

Usually, you'll want to add log entries to a buffer to be periodically flushed (automatically and asynchronously) to the Cloud Logging service. [snip]:# (logging-2)

logger
 :=
 client
.
Logger
(
"my-log"
)
logger
.
Log
(logging.
Entry
{
Payload
: 
"something happened!"
})

If you need to write a critical log entry use synchronous ingestion method. [snip]:# (logging-3)

logger
 :=
 client
.
Logger
(
"my-log"
)
logger
.
LogSync
(
context
.
Background
(), logging.
Entry
{
Payload
: 
"something happened!"
})

Close your client before your program exits, to flush any buffered log entries. [snip]:# (logging-4)

err
 =
 client
.
Close
()
if
 err
 !=
 nil
 {
   
// TODO: Handle error.

}

Logger configuration options

Creating a Logger using logging.Logger accept configuration LoggerOption arguments. The following options are supported:

Configuration option Arguments Description
CommonLabels map[string]string The set of labels that will be ingested for all log entries ingested by Logger.
ConcurrentWriteLimit int Number of parallel goroutine the Logger will use to ingest logs asynchronously. High number of routines may exhaust API quota. The default is 1.
DelayThreshold time.Duration Maximum time a log entry is buffered on client before being ingested. The default is 1 second.
EntryCountThreshold int Maximum number of log entries to be buffered on client before being ingested. The default is 1000.
EntryByteThreshold int Maximum size in bytes of log entries to be buffered on client before being ingested. The default is 8MiB.
EntryByteLimit int Maximum size in bytes of the single write call to ingest log entries. If EntryByteLimit is smaller than EntryByteThreshold, the latter has no effect. The default is zero, meaning there is no limit.
BufferedByteLimit int Maximum number of bytes that the Logger will keep in memory before returning ErrOverflow. This option limits the total memory consumption of the Logger (but note that each Logger has its own, separate limit). It is possible to reach BufferedByteLimit even if it is larger than EntryByteThreshold or EntryByteLimit, because calls triggered by the latter two options may be enqueued (and hence occupying memory) while new log entries are being added.
ContextFunc func() (ctx context.Context, afterCall func()) Callback function to be called to obtain context.Context during async log ingestion.
SourceLocationPopulation One of logging.DoNotPopulateSourceLocation , logging.PopulateSourceLocationForDebugEntries or logging.AlwaysPopulateSourceLocation Controls auto-population of the logging.Entry.SourceLocation field when ingesting log entries. Allows to disable population of source location info, allowing it only for log entries at Debug severity or enable it for all log entries. Enabling it for all entries may result in degradation in performance. Use logging_test.BenchmarkSourceLocationPopulation to test performance with and without the option. The default is set to logging.DoNotPopulateSourceLocation .
PartialSuccess Make each write call to Logging service with partialSuccess flag set. The default is to make calls without setting the flag.
RedirectAsJSON io.Writer Converts log entries to Jsonified one line string according to the structured logging format and writes it to provided io.Writer . Users should use this option with os.Stdout and os.Stderr to leverage the out-of-process ingestion of logs using logging agents that are deployed in Cloud Logging environments.
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본