📜 ⬆️ ⬇️

Vader - simple logger for dart

A few days ago I decided to feel the state at which time the Dart language was represented some time ago. The easiest way, in my opinion, to try the possibilities of a language is to write something simple and complete on it. Without thinking twice, I decided to write a simple logger for Dart in object-oriented style. Under the cut out my impression of Dart and a brief description of what happened.

Dart, as you know, is under active development and currently has:
  1. Virtual machine to execute code locally
  2. Dart-code translator to Javascript
  3. A simple development environment Dart Editor, built on the basis of Eclipse and in the alpha version stage.
  4. A specialized Chromium assembly called Dartium, which allows you to run Dart applications, without being translated into Javascript.

Impressions of the language itself


The easiest thing in my opinion is to write in Dart to anyone who has ever written in Java, because the Dart syntax borrowed a lot from this language. However, this gives rise to the feeling that someone was very abused over Java:

Impressions from the development environment


It's all very simple - the environment is damp and with a lot of bugs. First of all, the bad work of autocompletion and code highlighting are annoying. For example, autocompletion refuses to show closed class methods within the class itself. Although the Java support provided by Eclipse DartEditor is still far away, the environment nevertheless catches the most obvious errors related to the incorrect import of libraries or syntax errors in the code. It even shows some features of the standard Dart library - for example, that you cannot simultaneously import client (dart: html) and server libraries (dart: io).

Promised Sample Code


Notwithstanding the fact that similar functionality is available in the standard library, I wrote a very simple logger that allows you to output messages with different levels of logging (Debug, Info, Alert, etc.) to various output streams. The main abstractions used in the logger are:

At the moment, 3 output streams are implemented:
Using the logger is very simple:
#import("vader_server.dart"); void main(){ Vader vader = Vader.vader(new StdoutStream()); vader.logWarn("You don't know the power of the dark side!"); vader.logInfo("Luke, I am your father!"); } 

To get started, just import one of the library files: vader_server.dart (for logging to a file) or vader_client.dart (for logging in a browser). This separation is due to the fact that it is impossible to import client and server libraries into Dart at the same time. The logger code, provided with comments, can be viewed at this link .

')

Source: https://habr.com/ru/post/152333/


All Articles