在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):touchlab/Kermit开源软件地址(OpenSource Url):https://github.com/touchlab/Kermit开源编程语言(OpenSource Language):Kotlin 83.1%开源软件介绍(OpenSource Introduction):Kermit the logKermit is a Kotlin Multiplatform logging utility with composable log outputs. Out of the box, the library defaults to platform-specific loggers such as Logcat and OSLog, but is easy to extend and configure.
Most Users Read ThisIf you don't care about the philosophy of logging, custom configurations, and especially if you're writing for native mobile (KMM), then you should just do the following. Add DependencyThe Kermit dependency should be added to your commonMain {
dependencies {
implementation(kotlin("stdlib-common"))
implementation("co.touchlab:kermit:x.y.z") //Add latest version
}
} LogLogger.i { "Hello World" } The rest of the docs explain more detailed options, but at this point you should be able to log from common code. DefaultsBy default, Kermit adds one Logger instance. The choice of default logger is basically the best option for local development. On Android, it is Logcat, for JS it just logs to console. On iOS, the logs go to OSLog but also get some visual style to help hightlight the severity. Production deployments may want a different configuration. Basic ConceptsThe basic components you'll need to be aware of are LoggerThe You configure the LogWriterA Kermit includes a For more info on included SeveritySeverity levels follow common logging library patterns and should be generally familiar. You can control what will
and won't get logged based on severity. So, say you only want to log UsageYou call logging methods on a In its most basic form, logging looks like this: Logger.i { "Hello World" } If you are not familiar with the curly bracket syntax, that is a trailing lambda with special syntax. Again, that will not be evaluated if no log writer needs it. String creation can be relatively costly if you don't need it, so Kermit will avoid creating the string if it is not being logged. The call above is on the global A Note About TagsTags are a complicating factor in the design. Currently tags are part of the Logger instance because we found the tag param to be kind of verbose and Android-specific. We also wanted to keep the number of api methods to a minimum because Swift (and others) can't handle default parameters, so each log statement requires all parameters in the call. However, if just using the global logger instance, having no tag parameter is a problem. We may be adding tag as a param but only for the global instance. Stay tuned (or comment in discussions). LocalLocal usage is basically the same in concept. You simply call the same method on a local instance. val logger = Logger.withTag("MyLogger")
logger.i { "Hello World" } You can supply a different tag for the logger through local instances. This is more meaningful in an Android context. As mentioned, there's also a slight performance advantage to local. See PERFORMANCE for more info. ConfigurationYou can configure two parameters for LoggerConfig: LogWriter InstancesBy default, only the Logger.setLogWriters(platformLogWriter()) For more fine-grained control, you can supply log writers individually. See LOG_WRITER. Default TagThe default tag is the tag used while logging if you have no changed a Logger-specific tag. By default, it is "Kermit". You can change the default global tag with: Logger.setDefaultTag("MyTag") Minimum SeverityTo avoid logging lower level statements, you can set a minimum severity. This will prevent evaluating log message lambdas for those severities. To configure the global minimum severity, add: Logger.setMinSeverity(Severity.Warn) You may only want to turn this on in production, or by some other flag. Be careful, as it'll be easy to turn this on and forget, then not see debug log statements. For that reason, it is probably best left alone unless in a production situation. Local ConfigurationThe configuration above is on the global instance. For a number of reason, you may want a local val logger = Logger(StaticConfig(minSeverity = Severity.Warn, loggerList = listOf(CommonWriter())))
logger.i { "Hello Local!" } See PERFORMANCE for more info. TagsEach Tags are passed to You can override the global default tag (see Default Tag). To have a tag other than default, create a new val newTagLogger = logger.withTag("newTag") iOSGenerally speaking, Kermit's SDK was designed to be called from Kotlin, but you can initialize and call logging from any platform that has interop with Kotlin. For iOS and Swift-specific considerations, see IOS_CONSIDERATIONS SamplesThere are multiple sample apps showing various configurations. Crash ReportingKermit includes crash reporting implementations for Crashlytics and Bugsnag. These will write breadcrumb statements to those crash reporting tools, and can be triggered to report unhandled crash reports when there's an uncaught Kotlin exception.
SentrySentry support exists but is experimental. We've had some reports of issues, so we may pull support until there are people available to look at it. Other users have it in production, so just be aware and verify that it works in your app. TestingKermit includes a test dependency, intended for use when testing application code that interacts with Kermit APIs but
doesn't want to write to actual logs. This includes a Kermit ChiselFor some situations, disabling logging is desirable. For example, when building release versions of apps. You can disable logging by defining minSeverity on the logging config, but you can also run a compiler plugin and strip out logging calls entirely. To run the log strip plugin, add the classpath to your buildscript: buildscript {
dependencies {
classpath("co.touchlab:kermit-gradle-plugin:x.y.z")
}
} Then apply the plugin in your gradle file: plugins {
id("co.touchlab.kermit")
//etc
} By default, running the plugin does nothing. You should configure the plugin with a severity: kermit {
stripBelow = StripSeverity.Warn
} Any log call below the configured severity will be removed. So, if you pass See the "sample-chisel" example. You can change the In our production applications, we generally send error and warning level throwables to remote crash reporters, info level is tracked in "breadcrumbs" for remote crash reporters. Debug and verbose are local-only. Sticking to that pattern, you could configure your build as follows: val releaseBuild: String by project
kermit {
if(releaseBuild.toBoolean()) {
stripBelow = StripSeverity.Info
}
} Add Note: Chisel is new and configuration is likely to change in the near future. Primary Maintainer |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论