Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

add lowercase versions of the constants #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 35 additions & 22 deletions lib/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,48 +271,61 @@ class Level implements Comparable<Level> {
const Level(this.name, this.value);

/// Special key to turn on logging for all levels ([value] = 0).
static const Level ALL = const Level('ALL', 0);
static const Level all = const Level('ALL', 0);
static const Level ALL = all;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest we go ahead and @deprecate all these.


/// Special key to turn off all logging ([value] = 2000).
static const Level OFF = const Level('OFF', 2000);
static const Level off = const Level('OFF', 2000);
static const Level OFF = off;

/// Key for highly detailed tracing ([value] = 300).
static const Level FINEST = const Level('FINEST', 300);
static const Level finest = const Level('FINEST', 300);
static const Level FINEST = finest;

/// Key for fairly detailed tracing ([value] = 400).
static const Level FINER = const Level('FINER', 400);
static const Level finer = const Level('FINER', 400);
static const Level FINER = finer;

/// Key for tracing information ([value] = 500).
static const Level FINE = const Level('FINE', 500);
static const Level fine = const Level('FINE', 500);
static const Level FINE = fine;

/// Key for static configuration messages ([value] = 700).
static const Level CONFIG = const Level('CONFIG', 700);
static const Level config = const Level('CONFIG', 700);
static const Level CONFIG = config;

/// Key for informational messages ([value] = 800).
static const Level INFO = const Level('INFO', 800);
static const Level info = const Level('INFO', 800);
static const Level INFO = info;

/// Key for potential problems ([value] = 900).
static const Level WARNING = const Level('WARNING', 900);
static const Level warning = const Level('WARNING', 900);
static const Level WARNING = warning;

/// Key for serious failures ([value] = 1000).
static const Level SEVERE = const Level('SEVERE', 1000);
static const Level severe = const Level('SEVERE', 1000);
static const Level SEVERE = severe;

/// Key for extra debugging loudness ([value] = 1200).
static const Level SHOUT = const Level('SHOUT', 1200);

static const List<Level> LEVELS = const [
ALL,
FINEST,
FINER,
FINE,
CONFIG,
INFO,
WARNING,
SEVERE,
SHOUT,
OFF
static const Level shout = const Level('SHOUT', 1200);
static const Level SHOUT = shout;

/// The list of all the predefined logging levels.
static const List<Level> levels = const [
all,
finest,
finer,
fine,
config,
info,
warning,
severe,
shout,
off,
];

static const List<Level> LEVELS = levels;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And deprecate this too. 👍


@override
bool operator ==(Object other) => other is Level && value == other.value;
bool operator <(Level other) => value < other.value;
Expand Down
118 changes: 59 additions & 59 deletions test/logging_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main() {
});

test('default levels are in order', () {
final levels = Level.LEVELS;
final levels = Level.levels;

for (int i = 0; i < levels.length; i++) {
for (int j = i + 1; j < levels.length; j++) {
Expand All @@ -41,19 +41,19 @@ void main() {

test('levels are comparable', () {
final unsorted = [
Level.INFO,
Level.CONFIG,
Level.FINE,
Level.SHOUT,
Level.OFF,
Level.FINER,
Level.ALL,
Level.WARNING,
Level.FINEST,
Level.SEVERE,
Level.info,
Level.config,
Level.fine,
Level.shout,
Level.off,
Level.finer,
Level.all,
Level.warning,
Level.finest,
Level.severe,
];

final sorted = Level.LEVELS;
final sorted = Level.levels;

expect(unsorted, isNot(orderedEquals(sorted)));

Expand All @@ -63,10 +63,10 @@ void main() {

test('levels are hashable', () {
var map = new Map<Level, String>();
map[Level.INFO] = 'info';
map[Level.SHOUT] = 'shout';
expect(map[Level.INFO], same('info'));
expect(map[Level.SHOUT], same('shout'));
map[Level.info] = 'info';
map[Level.shout] = 'shout';
expect(map[Level.info], same('info'));
expect(map[Level.shout], same('shout'));
});

test('logger name cannot start with a "." ', () {
Expand Down Expand Up @@ -124,7 +124,7 @@ void main() {
});

test('stackTrace gets throw to LogRecord', () {
Logger.root.level = Level.INFO;
Logger.root.level = Level.info;

var records = new List<LogRecord>();

Expand All @@ -133,11 +133,11 @@ void main() {
try {
throw new UnsupportedError('test exception');
} catch (error, stack) {
Logger.root.log(Level.SEVERE, 'severe', error, stack);
Logger.root.log(Level.severe, 'severe', error, stack);
Logger.root.warning('warning', error, stack);
}

Logger.root.log(Level.SHOUT, 'shout');
Logger.root.log(Level.shout, 'shout');

sub.cancel();

Expand Down Expand Up @@ -199,7 +199,7 @@ void main() {
recordingZone = Zone.current;
});

runZoned(() => root.log(Level.INFO, 'hello', null, null, recordingZone));
runZoned(() => root.log(Level.info, 'hello', null, null, recordingZone));

expect(records, hasLength(1));
expect(records.first.zone, equals(recordingZone));
Expand Down Expand Up @@ -238,7 +238,7 @@ void main() {

setUp(() {
hierarchicalLoggingEnabled = true;
root.level = Level.INFO;
root.level = Level.info;
a.level = null;
b.level = null;
c.level = null;
Expand All @@ -251,55 +251,55 @@ void main() {
d.clearListeners();
e.clearListeners();
hierarchicalLoggingEnabled = false;
root.level = Level.INFO;
root.level = Level.info;
});

test('cannot set level if hierarchy is disabled', () {
expect(() {
a.level = Level.FINE;
a.level = Level.fine;
}, throwsUnsupportedError);
});

test('loggers effective level - no hierarchy', () {
expect(root.level, equals(Level.INFO));
expect(a.level, equals(Level.INFO));
expect(b.level, equals(Level.INFO));
expect(root.level, equals(Level.info));
expect(a.level, equals(Level.info));
expect(b.level, equals(Level.info));

root.level = Level.SHOUT;
root.level = Level.shout;

expect(root.level, equals(Level.SHOUT));
expect(a.level, equals(Level.SHOUT));
expect(b.level, equals(Level.SHOUT));
expect(root.level, equals(Level.shout));
expect(a.level, equals(Level.shout));
expect(b.level, equals(Level.shout));
});

test('loggers effective level - with hierarchy', () {
hierarchicalLoggingEnabled = true;
expect(root.level, equals(Level.INFO));
expect(a.level, equals(Level.INFO));
expect(b.level, equals(Level.INFO));
expect(c.level, equals(Level.INFO));

root.level = Level.SHOUT;
b.level = Level.FINE;

expect(root.level, equals(Level.SHOUT));
expect(a.level, equals(Level.SHOUT));
expect(b.level, equals(Level.FINE));
expect(c.level, equals(Level.FINE));
expect(root.level, equals(Level.info));
expect(a.level, equals(Level.info));
expect(b.level, equals(Level.info));
expect(c.level, equals(Level.info));

root.level = Level.shout;
b.level = Level.fine;

expect(root.level, equals(Level.shout));
expect(a.level, equals(Level.shout));
expect(b.level, equals(Level.fine));
expect(c.level, equals(Level.fine));
});

test('isLoggable is appropriate', () {
hierarchicalLoggingEnabled = true;
root.level = Level.SEVERE;
c.level = Level.ALL;
root.level = Level.severe;
c.level = Level.all;
e.level = Level.OFF;

expect(root.isLoggable(Level.SHOUT), isTrue);
expect(root.isLoggable(Level.SEVERE), isTrue);
expect(root.isLoggable(Level.WARNING), isFalse);
expect(c.isLoggable(Level.FINEST), isTrue);
expect(c.isLoggable(Level.FINE), isTrue);
expect(e.isLoggable(Level.SHOUT), isFalse);
expect(root.isLoggable(Level.shout), isTrue);
expect(root.isLoggable(Level.severe), isTrue);
expect(root.isLoggable(Level.warning), isFalse);
expect(c.isLoggable(Level.finest), isTrue);
expect(c.isLoggable(Level.fine), isTrue);
expect(e.isLoggable(Level.shout), isFalse);
});

test('add/remove handlers - no hierarchy', () {
Expand Down Expand Up @@ -331,7 +331,7 @@ void main() {
});

test('logging methods store appropriate level', () {
root.level = Level.ALL;
root.level = Level.all;
var rootMessages = [];
root.onRecord.listen((record) {
rootMessages.add('${record.level}: ${record.message}');
Expand Down Expand Up @@ -361,7 +361,7 @@ void main() {
});

test('logging methods store exception', () {
root.level = Level.ALL;
root.level = Level.all;
var rootMessages = [];
root.onRecord.listen((r) {
rootMessages.add('${r.level}: ${r.message} ${r.error}');
Expand Down Expand Up @@ -407,7 +407,7 @@ void main() {
});

test('message logging - no hierarchy', () {
root.level = Level.WARNING;
root.level = Level.warning;
var rootMessages = [];
var aMessages = [];
var cMessages = [];
Expand Down Expand Up @@ -457,7 +457,7 @@ void main() {
test('message logging - with hierarchy', () {
hierarchicalLoggingEnabled = true;

b.level = Level.WARNING;
b.level = Level.warning;

var rootMessages = [];
var aMessages = [];
Expand Down Expand Up @@ -524,7 +524,7 @@ void main() {
});

test('message logging - lazy functions', () {
root.level = Level.INFO;
root.level = Level.info;
var messages = [];
root.onRecord.listen((record) {
messages.add('${record.level}: ${record.message}');
Expand All @@ -546,7 +546,7 @@ void main() {
});

test('message logging - calls toString', () {
root.level = Level.INFO;
root.level = Level.info;
var messages = [];
var objects = [];
var object = new Object();
Expand Down Expand Up @@ -602,7 +602,7 @@ void main() {

test('trace recorded only on requested levels', () {
var records = new List<LogRecord>();
recordStackTraceAtLevel = Level.WARNING;
recordStackTraceAtLevel = Level.warning;
root.onRecord.listen(records.add);
root.severe('hello');
root.warning('hello');
Expand All @@ -616,7 +616,7 @@ void main() {
test('provided trace is used if given', () {
var trace = StackTrace.current;
var records = new List<LogRecord>();
recordStackTraceAtLevel = Level.WARNING;
recordStackTraceAtLevel = Level.warning;
root.onRecord.listen(records.add);
root.severe('hello');
root.warning('hello', 'a', trace);
Expand All @@ -627,7 +627,7 @@ void main() {

test('error also generated when generating a trace', () {
var records = new List<LogRecord>();
recordStackTraceAtLevel = Level.WARNING;
recordStackTraceAtLevel = Level.warning;
root.onRecord.listen(records.add);
root.severe('hello');
root.warning('hello');
Expand Down