question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting started with Logging

See original GitHub issue

I’m having some difficulty getting started with nuget Google.Logging.V2. Sadly, this is still empty: https://github.com/GoogleCloudPlatform/google-cloud-dotnet#google-cloud-logging

I was able to get our Go app working with Google Logging last week using my fork of a Logrus hook. Now, I want to get the .NET client working since we have many more F# projects. Many of them are using NLog http://nlog-project.org/. I would be great to have an NLog Target for Google Logging.

I just got this to actually write log messages:

module glog

open System.Collections.Generic

// https://github.com/GoogleCloudPlatform/google-cloud-dotnet/blob/master/apis/Google.Logging.V2/Google.Logging.Log4Net/Extensions.cs
let epochZero = System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc)

let toTimestamp(dt: System.DateTime) =
    let sinceEpoch = dt - epochZero
    Google.Protobuf.WellKnownTypes.Timestamp(
        Seconds = sinceEpoch.Ticks / System.TimeSpan.TicksPerSecond,
        Nanos = (int)((sinceEpoch.Ticks % System.TimeSpan.TicksPerSecond) * (1000000000L / System.TimeSpan.TicksPerSecond))
    )

[<EntryPoint>]
let main argv =
    // https://github.com/GoogleCloudPlatform/google-cloud-dotnet#google-cloud-logging
    // https://github.com/GoogleCloudPlatform/google-cloud-dotnet/blob/master/apis/Google.Logging.V2/Google.Logging.Log4Net/GoogleStackdriverAppender.cs

    let client = Google.Logging.V2.LoggingServiceV2Client.Create()
    let rs = Google.Api.MonitoredResource(Type="global")

    let logName = Google.Logging.V2.LoggingServiceV2Client.FormatLogName("tachyusatmion", "fsharp-test")

    let le = Google.Logging.V2.LogEntry()
    le.TextPayload <- "2016-10-20 payload"
    le.InsertId <- sprintf "%s:%d" (System.Guid.NewGuid().ToString()) 1
    le.Severity <- Google.Logging.Type.LogSeverity.Debug
    le.Timestamp <- toTimestamp(System.DateTime.UtcNow)

    // let cs = Google.Api.Gax.CallSettings()

    let rsp = client.WriteLogEntries(logName, rs, Dictionary(), [le])

    printfn "%A" rsp
    0

Is it possible to see the http communication? I’m on my Mac. In Go, I’m able to os.Setenv("HTTPS_PROXY", "http://127.0.0.1:8080") and then start mitmproxy to see the communication. image screen shot 2016-10-20 at 9 20 22 am

Can I do something like that for this project? Is there a way to make the communication go through a proxy?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jskeetcommented, Oct 21, 2016

I agree it’s all a bit confusing, and that’s partly because it’s not “done” yet, and we have some documentation work still to do (both here on Github and on Google-owned sites).

They’re both autogenerated, at the moment - the Google.Logging.V2 library doesn’t have any wrapper code yet, although it might in the future.

In terms of pros and cons, referring to Google.Apis.Logging.v2 as the REST API and Google.Logging.V2 as the gRPC API:

  • The REST API is generated with stable codegen - it won’t change until the next major version, whereas the gRPC API is still in flux. We believe it works, so it’s functionally stable, but the API surface is still likely to change a bit before GA.
  • The gRPC codegen is designed to take more advantage of known semantics in the underlying API, and we’ve spent a lot of time trying to make it as usable as possible.
  • gRPC is more efficient than the REST API in terms of:
    • A binary format (protobuf) instead of JSON, for more efficient network transmission and parsing
    • Multiplexing over a single channel
    • More capabilities such as streaming, which isn’t used by logging but is used by other APIs such as Speech

In terms of gRPC debugging, you need two steps at the moment:

  • Set two environment variables, GRPC_TRACE=all and GRPC_VERBOSITY=debug
  • Call GrpcEnvironment.SetLogger in your code, e.g. GrpcEnvironment.SetLogger(new ConsoleLogger()) with suitable using directives

That will generate a lot of output - you can tinker with the environment variable values to limit the output.

0reactions
ctaggartcommented, Nov 28, 2016

fyi, I made a post about getting started with much of the above code in F# here: http://blog.ctaggart.com/2016/11/google-logging-from-log4net.html https://twitter.com/cmr0n/status/803290458474483712

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging HOWTO — Python 3.11.4 documentation
Logging is performed by calling methods on instances of the Logger class (hereafter called loggers). Each instance has a name, and they are...
Read more >
Logging in Python
Learn why and how to get started with Python's powerful logging module to meet the needs of beginners and enterprise teams alike.
Read more >
Getting Started with Logs
This page shows you how to get started with Log Management in Datadog. ... The lifecycle of a log within Datadog begins at...
Read more >
Python Logging Basics: How-To Tutorial, Examples & More
Logging in Python is a way to record information about your Python scripts and keep track of events generated by the scripts as...
Read more >
A Comprehensive Guide to Logging in Python
Logging is an invaluable tool for developing reliable software applications. It provides a way to record and track events in the software, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found