All Projects → DnV1eX → GoogleCloudLogging

DnV1eX / GoogleCloudLogging

Licence: Apache-2.0 license
Swift (Darwin) library for logging application events in Google Cloud.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to GoogleCloudLogging

deploy-cloudrun
This action deploys your container image to Cloud Run.
Stars: ✭ 238 (+891.67%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Googlecloudarchitectprofessional
Resources to prepare for Google Certified Cloud Architect Professional Exam - 2017
Stars: ✭ 177 (+637.5%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Fog Google
Fog for Google Cloud Platform
Stars: ✭ 83 (+245.83%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
All About Programming
Everything about programming!!
Stars: ✭ 314 (+1208.33%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
awesome-bigquery-views
Useful SQL queries for Blockchain ETL datasets in BigQuery.
Stars: ✭ 325 (+1254.17%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Cloud Functions Go
Unofficial Native Go Runtime for Google Cloud Functions
Stars: ✭ 427 (+1679.17%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Gcpsketchnote
If you are looking to become a Google Cloud Engineer , then you are at the right place. GCPSketchnote is series where I share Google Cloud concepts in quick and easy to learn format.
Stars: ✭ 2,631 (+10862.5%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Google-Cloud-Study-Jams
Resources for 30 Days of Google Cloud program workshops and events conducted by GDSC VJTI
Stars: ✭ 13 (-45.83%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Acho
The Hackable Log
Stars: ✭ 189 (+687.5%)
Mutual labels:  log, logger, debug
Cocoadebug
iOS Debugging Tool 🚀
Stars: ✭ 3,769 (+15604.17%)
Mutual labels:  log, logger, debug
augle
Auth + Google = Augle
Stars: ✭ 22 (-8.33%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
auth
A GitHub Action for authenticating to Google Cloud.
Stars: ✭ 567 (+2262.5%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
rowy
Open-source Airtable-like experience for your database (Firestore) with GCP's scalability. Build any automation or cloud functions for your product. ⚡️✨
Stars: ✭ 2,676 (+11050%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Grpc Gke Nlb Tutorial
gRPC load-balancing on GKE using Envoy
Stars: ✭ 42 (+75%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
restme
Template to bootstrap a fully functional, multi-region, REST service on GCP with a developer release pipeline.
Stars: ✭ 19 (-20.83%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Unity Solutions
Use Firebase tools to incorporate common features into your games!
Stars: ✭ 95 (+295.83%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
Cloud-Service-Providers-Free-Tier-Overview
Comparing the free tier offers of the major cloud providers like AWS, Azure, GCP, Oracle etc.
Stars: ✭ 226 (+841.67%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
argon
Campaign Manager 360 and Display & Video 360 Reports to BigQuery connector
Stars: ✭ 31 (+29.17%)
Mutual labels:  gcp, google-cloud, google-cloud-platform
debug.js
Debugger of JavaScript, by JavaScript, for JavaScript
Stars: ✭ 19 (-20.83%)
Mutual labels:  log, logger, debug
Logcat
Android 日志打印框架,在手机上可以直接看到 Logcat 日志啦
Stars: ✭ 189 (+687.5%)
Mutual labels:  log, logger, debug

GoogleCloudLogging

Event logging for client applications on Apple platforms with support for offline work and automatic upload to Google Cloud (GCP). The package depends on SwiftLog - an official logging API for Swift, so it can be easly integrated into the project and combined with other logging backends. Log events are stored locally in the JSON Lines file format and bulk uploaded to GCP using the Cloud Logging API v2 at time intervals, upon defined event or explicit request.

And yes, it logs itself! (with recursion protection) 🤘

Rationale

Google-recommended logging solution for client applications is the Analytics framework, which is now part of the Firebase SDK. Here is a comparison of their framework and this library in terms of logging:

Library FirebaseAnalytics GoogleCloudLogging
Platform Mobile only. Even Catalyst is not currently supported. All modern Apple's OSs. It is essential for development of universal SwiftUI apps.
Source code Closed source. All application and users data is available to Google. Open source. A few hundred lines of pure Swift, no implicit data submission.
Dependences Part of the Firebase SDK. Brings a bunch of Objective-C/C++ code with runtime swizzling etc. Only relies on SwiftLog and Apple's embedded frameworks.
Distribution CocoaPods/Carthage. SwiftPM is currently cannot be supported due to closed source and dependencies. SwiftPM, which is preferred as integrated with the Swift build system.
Backend Google Analytics for Firebase. Includes some predefined marketing tools. GCP Operations (formerly Stackdriver). Flexible custom log views, metrics, notifications, export etc.
Integration Registration of your app in Google is required. Only need to generate an access key.
Logging Proprietary logging functions and implicit usage tracking. SwiftLog logging API. Single line connection of logging backend.

Getting Started

Add Package Dependency

Open your application project in Xcode 11 or later, go to menu File -> Swift Packages -> Add Package Dependency... and paste the package repository URL https://github.com/DnV1eX/GoogleCloudLogging.git.

Create Service Account

In your web browser, open the Google Cloud Console and create a new project. In IAM & Admin -> Service Accounts create a service account choosing Logging -> Logs Writer role. In the last step, create and download private key choosing JSON format. You need to include this file in your application bundle.

Just drag the file into the Xcode project and tick the desired targets in the file inspector.

Setup Logging

  1. Import both SwiftLog and GoogleCloudLogging modules:
import Logging
import GoogleCloudLogging
  1. Register the logging backend once after the app launch:
LoggingSystem.bootstrap(GoogleCloudLogHandler.init)

Alternatively, you can register several backends, for example, in order to send logs to both GCP and the Xcode console:

LoggingSystem.bootstrap { MultiplexLogHandler([GoogleCloudLogHandler(label: $0), StreamLogHandler.standardOutput(label: $0)]) }
  1. Configure GoogleCloudLogHandler:
do {
    try GoogleCloudLogHandler.setup(serviceAccountCredentials: Bundle.main.url(forResource: /* GCP private key file name */, withExtension: "json")!, clientId: UIDevice.current.identifierForVendor)
} catch {
    // Log GoogleCloudLogHandler setup error
}

If UIKit is not available, you can generate random clientId using UUID() and store it between the app launches.

You can customize GoogleCloudLogHandler's static variables which are all thread safe and documented in the source code.

It is recommended to explicitly upload logs calling GoogleCloudLogHandler.upload() when hiding or exiting the app.

How to Use

Emit Logs

  1. Import SwiftLog module into the desired file:
import Logging
  1. Create logger which can be a type, instance, or global constant or variable:
static let logger = Logger(label: /* Logged class name */)

You can customize the minimum emitted log level and set the logger metadata.

  1. Emit log messages in a certain log level:
logger.info(/* Logged info message */)
logger.error(/* Logged error message */, metadata: [LogKey.error: "\(error)"])

It is a good practice to define typealias LogKey = GoogleCloudLogHandler.MetadataKey and extend it with your custom keys rather than use string literals.

GoogleCloudLogHandler.globalMetadata takes precedence over Logger metadata which in turn takes precedence over log message metadata in case of key overlapping.

Analyze Logs

In your web browser, open the GCP Operations Logging and select your project. You will see a list of logs for a given time range which can be filtered by log name (logger label), severity (log level), text payload (message), labels (metadata) etc. Resource type for logs produced by GoogleCloudLogHandler is always Global.

You can switch to the new Logs Viewer Preview that introduces new features, such as advanced log queries and histograms.

Click on clientId label value of the desired log entry and pick "Show matching entries" in order to view logs from the same app instance only.

Supported Platforms

  • iOS 11+
  • iPadOS 13+
  • macOS 10.13+
  • tvOS 11+
  • watchOS 4+

License

Copyright © 2020 DnV1eX. All rights reserved. Licensed under the Apache License, Version 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].