Name |
Ceylon Logging Platform Module |
---|---|
Description |
Defines a platform-neutral API for writing log messages. Important! By default, no log writer function is registered, and so nothing is logged. Read on to learn how to properly configure logging for your application Adding logging to your moduleLog messages are written to a Logger log = logger(`module hello`); The methods log.debug("trying to do something"); try { doSomething(); } catch (e) { log.error("something bad happened", e); } For log messages with interpolated expressions, these methods accept an anonymous function. log.debug(()=>"trying to do ``something``"); try { do(something); } catch (e) { log.error(()=>"badness happened doing ``something``", e); } Configuring logging for your applicationIf your module is going to be part of a larger application
then the above is the only thing you need to know to add
logging. But given the fact that this logging module does
not actually define any infrastructure for log message
output, your application must at some point during startup
register a addLogWriter(writeSimpleLog);
It's easy to customize the output by writing your own
log writer function. For example, we can
use import ceylon.logging { ... } import ceylon.time { now } import ceylon.locale { systemLocale } ... addLogWriter { void log(Priority p, Category c, String m, Throwable? t) { value print = p <= info then process.write else process.writeError; value instant = now(); value formats = systemLocale.formats; value date = formats.shortFormatDate(instant.date()); value time = formats.mediumFormatTime(instant.time()); print("[``date`` at ``time``] ``p.string``: ``m``"); print(operatingSystem.newline); if (exists t) { printStackTrace(t, print); } } }; Or, to log to a file, using import ceylon.logging { ... } import ceylon.file { ... } File file; switch (resource = parsePath("log.txt").resource) case (is ExistingResource) { assert (is File resource); file = resource; } case (is Nil) { file = resource.createFile(); } addLogWriter { void log(Priority p, Category c, String m, Throwable? t) { try (appender = file.Appender()) { appender.writeLine("[``system.milliseconds``] ``p.string``: ``m``"); if (exists t) { printStackTrace(t, appender.write); } } } }; By default, only log messages with priority at least
defaultPriority = debug; Alternatively, we can assign an explicit priority to a
specific logger(`module hello`).priority = debug; For integration with other logging libraries, it is
possible to completely replace the logger = (Category category) => JDKLoggerImpl(JDKLogger.getLogger(category.qualifiedName)); |
Category |
SDK
The Ceylon SDK |
Last Published | Aug 21, 2017 |
Stats |
Downloads (JVM): 7239 Downloads (JS): 1089 Source downloads: 4749 |
Module links |
Home Code repository Issue tracker Imported By Browse |
1.3.3 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) | Published Aug 21, 2017 |
Browse |
View docs |
|
1.3.2 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) | Published Mar 1, 2017 |
Browse |
View docs |
|
1.3.1 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) | Published Nov 21, 2016 |
Browse |
View docs |
|
1.3.0 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) | Published Sep 15, 2016 |
Browse |
View docs |
|
1.2.2 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) | Published Mar 11, 2016 |
Browse |
View docs |
|
1.2.1 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) | Published Feb 11, 2016 |
Browse |
View docs |
|
1.2.0 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.0 (outdated) | Published Oct 28, 2015 |
Browse |
View docs |
|
1.1.0 | JVM JavaScript JVM: 1.1.0 (outdated) JavaScript: 1.1.0 (outdated) | Published Oct 8, 2014 |
Browse |
View docs |