Skip to content

Commit

Permalink
Add proposal file
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylEnkidu committed Jul 8, 2024
1 parent eca84fd commit a7e048a
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
89 changes: 89 additions & 0 deletions FirebaseSharedSwift/Sources/FirebaseInternalLog.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
import OSLog

protocol FirebaseInternalLog {
func notice(_ message: String)

func info(_ message: String)

func debug(_ message: String)

func warning(_ message: String)

func error(_ message: String)

func fault(_ message: String)
}

extension OSLog: FirebaseInternalLog {
func notice(_ message: String) {
os_log("%s", log: self, type: .default, message)
}

func info(_ message: String) {
os_log("%s", log: self, type: .info, message)
}

func debug(_ message: String) {
os_log("%s", log: self, type: .debug, message)
}

func warning(_ message: String) {
os_log("%s", log: self, type: .default, message)
}

func error(_ message: String) {
os_log("%s", log: self, type: .error, message)
}

func fault(_ message: String) {
os_log("%s", log: self, type: .fault, message)
}
}

@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
class FirebaseInternalLogger: FirebaseInternalLog {
private let logger: Logger

required init(subsystem: String, category: String) {
logger = Logger(subsystem: subsystem, category: category)
}

func notice(_ message: String) {
logger.notice("\(message)")
}

func info(_ message: String) {
logger.info("\(message)")
}

func debug(_ message: String) {
logger.debug("\(message)")
}

func warning(_ message: String) {
logger.warning("\(message)")
}

func error(_ message: String) {
logger.error("\(message)")
}

func fault(_ message: String) {
logger.fault("\(message)")
}
}
66 changes: 66 additions & 0 deletions FirebaseSharedSwift/Sources/FirebaseLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
import OSLog

public struct FirebaseProduct {
var name: String

public init(name: String) {
self.name = name
}
}

public class FirebaseLogger {
let subsystem: String = "com.google.firebase"

let firebaseProduct: FirebaseProduct

private lazy var logger: FirebaseInternalLog = {
if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
return FirebaseInternalLogger(subsystem: subsystem, category: firebaseProduct.name)
} else {
return OSLog(subsystem: subsystem, category: firebaseProduct.name)
}
}()

public init(firebaseProduct: FirebaseProduct) {
self.firebaseProduct = firebaseProduct
}

public func notice(_ message: String) {
logger.notice(message)
}

public func info(_ message: String) {
logger.info(message)
}

public func debug(_ message: String) {
logger.debug(message)
}

public func warning(_ message: String) {
logger.warning(message)
}

public func error(_ message: String) {
logger.error(message)
}

public func fault(_ message: String) {
logger.fault(message)
}
}
31 changes: 31 additions & 0 deletions FirebaseSharedSwift/Tests/FirebaseLoggerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import FirebaseSharedSwift
import Foundation

// MARK: - Test Suite

import XCTest

extension FirebaseProduct {
static let testLogger = FirebaseProduct(name: "firebase_logger_test")
}

class TestFirebaseLogger: XCTestCase {
func testLoggerUsage() {
let testLogger = FirebaseLogger(firebaseProduct: FirebaseProduct.testLogger)
testLogger.debug("Set up successfully!")
}
}

0 comments on commit a7e048a

Please sign in to comment.