Book Image

Dart By Example

By : David Mitchell
Book Image

Dart By Example

By: David Mitchell

Overview of this book

Table of Contents (17 chapters)
Dart By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Logging


Web servers such as Apache and IIS track a visitor's web browser usage, which helps webmasters understand how visitors use their site and how many people view the pages. This good practice also helps web developers find problems in their site and helps the developers of a web server software diagnose issues.

Tip

For general-purpose logging in your Dart applications, take a look at the logging package, which is authored by the Dart team and is available at

https://pub.dartlang.org/packages/logging.

Writing text files

With dart:io, we already read files from the file system, and writing operates in a similar manner, as follows:

import 'dart:io';

void main() {
  File myfile = new File("example.txt");
  myfile.writeAsStringSync("Hello Word!");
}

This demonstrates the synchronous version of the function, with writeAsString being the asynchronous version.

Open the log.dart file in this chapter's project. For this, take a look at the following code snippet:

void log(HttpRequest request) {
  String...