Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement logger service #132

Merged
merged 7 commits into from
Sep 7, 2023
Merged
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
2 changes: 2 additions & 0 deletions lib/internal/console/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Console
This directory contains the implementation of the mineral command line interface.
2 changes: 2 additions & 0 deletions lib/internal/services/intents/intents.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ class Intents {

/// Creates an [Intents] service with the intents defined in the builder.
factory Intents.builder(Function(IntentBuilder) builder) => Intents._(builder(IntentBuilder()).intents);

int get calculatedValue => _intents.fold(0, (previousValue, element) => previousValue += element.value);
}
30 changes: 30 additions & 0 deletions lib/services/logger/logger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:io';

import 'package:mineral/services/logger/logger_contract.dart';
import 'package:tint/tint.dart';

class Logger implements LoggerContract {
@override
void debug(String message) =>
stdout.writeln('${'[ debug ]'.grey()} $message');

@override
void error(String message) =>
stdout.writeln('${'[ error ]'.red()} $message');

@override
void info(String message) =>
stdout.writeln('${'[ info ]'.cyan()} $message');

@override
void log(message) =>
stdout.writeln('[log] $message');

@override
void success(String message) =>
stdout.writeln('${'[ success ]'.green()} $message');

@override
void warning(String message) =>
stdout.writeln('${'[ warning ]'.yellow()} $message');
}
13 changes: 13 additions & 0 deletions lib/services/logger/logger_contract.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract interface class LoggerContract {
void log(dynamic message);

void error(String message);

void warning(String message);

void success(String message);

void info(String message);

void debug(String message);
}
8 changes: 8 additions & 0 deletions test/functionals/intent_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ void main () {
final Intents service = Intents.none();
expect(service.intents, isEmpty);
});

test('can create Intent service without intents', () {
final List<Intent> intents = [Intent.guilds, Intent.directMessages];
final Intents service = Intents.only(intents);

expect(service.intents, allOf([hasLength(2), containsAll(intents)]));
expect(service.calculatedValue, equals(4097));
});
}