Getting started with Logging
See original GitHub issueI’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.
Can I do something like that for this project? Is there a way to make the communication go through a proxy?
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
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:
In terms of gRPC debugging, you need two steps at the moment:
GRPC_TRACE=all
andGRPC_VERBOSITY=debug
GrpcEnvironment.SetLogger
in your code, e.g.GrpcEnvironment.SetLogger(new ConsoleLogger())
with suitableusing
directivesThat will generate a lot of output - you can tinker with the environment variable values to limit the output.
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