From 6ea15aba7ad23cbb01102f86e2ae2214c01b6f07 Mon Sep 17 00:00:00 2001 From: Kevin Schildhorn Date: Fri, 15 Nov 2024 16:49:34 -0500 Subject: [PATCH] Revert "Removing Logger from sample" This reverts commit 1c97ee62b358a551e84427f5f9321b21fa72de2f. --- .../KermitSampleIOS/ContentView.swift | 4 +-- .../co/touchlab/KermitSample/FirstFragment.kt | 4 +-- samples/sample/shared/build.gradle.kts | 21 ++++++++++++-- .../co/touchlab/kermitsample/SampleMobile.kt | 29 +++++++++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 samples/sample/shared/src/mobileMain/kotlin/co/touchlab/kermitsample/SampleMobile.kt diff --git a/samples/sample/KermitSampleIOS/KermitSampleIOS/ContentView.swift b/samples/sample/KermitSampleIOS/KermitSampleIOS/ContentView.swift index c18af835..56cdb73e 100644 --- a/samples/sample/KermitSampleIOS/KermitSampleIOS/ContentView.swift +++ b/samples/sample/KermitSampleIOS/KermitSampleIOS/ContentView.swift @@ -15,14 +15,14 @@ import shared struct ContentView: View { - let common: CommonMobile + let common: SampleMobile init() { let filePath = NSHomeDirectory() + "/Documents/" let fileName = "KermitSampleLogs" ContentView.createLoggingFile(withName: fileName, atPath: filePath) - self.common = CommonMobile() + self.common = SampleMobile(filePathString: filePath, logFileName: fileName) } private static func createLoggingFile(withName name:String, atPath filePath: String){ diff --git a/samples/sample/app/src/main/java/co/touchlab/KermitSample/FirstFragment.kt b/samples/sample/app/src/main/java/co/touchlab/KermitSample/FirstFragment.kt index 47228420..116e8c6a 100644 --- a/samples/sample/app/src/main/java/co/touchlab/KermitSample/FirstFragment.kt +++ b/samples/sample/app/src/main/java/co/touchlab/KermitSample/FirstFragment.kt @@ -15,7 +15,7 @@ import android.view.View import androidx.fragment.app.Fragment import co.touchlab.KermitSample.databinding.FragmentFirstBinding import co.touchlab.kermit.Logger -import co.touchlab.kermitsample.SampleCommon +import co.touchlab.kermitsample.SampleMobile /** * A simple [Fragment] subclass as the default destination in the navigation. @@ -25,7 +25,7 @@ class FirstFragment : Fragment(R.layout.fragment_first) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) Logger.withTag("FirstFragment").v("First fragment loaded") - val sample = SampleCommon() + val sample = SampleMobile(context?.filesDir?.path ?: "") val binding = FragmentFirstBinding.bind(view) binding.btnClickCount.setOnClickListener { sample.onClickI() } binding.btnException.setOnClickListener { sample.logException() } diff --git a/samples/sample/shared/build.gradle.kts b/samples/sample/shared/build.gradle.kts index 92de0620..76957897 100644 --- a/samples/sample/shared/build.gradle.kts +++ b/samples/sample/shared/build.gradle.kts @@ -59,9 +59,24 @@ kotlin { implementation("co.touchlab:kermit-test:${KERMIT_VERSION}") } - iosMain.dependencies { - // Only if you want to talk to Kermit from Swift - api("co.touchlab:kermit-simple:${KERMIT_VERSION}") + val mobileMain by creating { + dependsOn(commonMain.get()) + dependencies { + implementation("co.touchlab:kermit-io:${KERMIT_VERSION}") + } + } + androidMain { + dependsOn(mobileMain) + } + iosMain { + dependsOn(mobileMain) + iosX64Main.get().dependsOn(this) + iosArm64Main.get().dependsOn(this) + iosSimulatorArm64Main.get().dependsOn(this) + dependencies { + // Only if you want to talk to Kermit from Swift + api("co.touchlab:kermit-simple:${KERMIT_VERSION}") + } } } cocoapods { diff --git a/samples/sample/shared/src/mobileMain/kotlin/co/touchlab/kermitsample/SampleMobile.kt b/samples/sample/shared/src/mobileMain/kotlin/co/touchlab/kermitsample/SampleMobile.kt new file mode 100644 index 00000000..297bfd7a --- /dev/null +++ b/samples/sample/shared/src/mobileMain/kotlin/co/touchlab/kermitsample/SampleMobile.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Touchlab + * 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. + */ + +package co.touchlab.kermitsample + +import co.touchlab.kermit.Logger +import co.touchlab.kermit.io.RollingFileLogWriter +import co.touchlab.kermit.io.RollingFileLogWriterConfig +import kotlinx.io.files.Path + +class SampleMobile(filePathString: String, logFileName: String = "KermitSampleLogs") : SampleCommon() { + init { + Logger.addLogWriter( + RollingFileLogWriter( + config = RollingFileLogWriterConfig( + logFileName = logFileName, + logFilePath = Path(filePathString), + ) + ) + ) + } +} \ No newline at end of file