Jim Belton
Jim Belton

Reputation: 231

How do I import the logging library in Dart?

If I run:

#!/home/jim/dart/dart-sdk/bin/dart

#import('logging');

Logger log = new Logger('');

void main() {
    log.warn("Hello, world!\n");
}

I get:

Unable to open file: /home/jim/Code/dart/test/logging'file:///home/jim/Code/dart/test/test-log.dart': Error: line 3 pos 1: library handler failed

Do I need to install the logger library? Where can I find it? How do I import it?

Upvotes: 3

Views: 1786

Answers (1)

Justin Fagnani
Justin Fagnani

Reputation: 11201

Use pub, the package manager for Dart.

In your pubspec.yaml, make sure you have a line for logging in the dependencies section:

name: mylib
description: My Library
dependencies:
  logging: any

Then run pub install, either in the Editor (Tools->Pub Install), or from the command line (./dart/dart-sdk/bin/pub install)

Then you can import logging with the package: scheme:

import 'package:logging/logging.dart';

Upvotes: 3

Related Questions