Skip to content

Commit

Permalink
🎗️ Added Session Logger.
Browse files Browse the repository at this point in the history
Every release mode run of the app writes its log into `~/.config/cliptopia/session.log` file.
  • Loading branch information
omegaui committed Dec 26, 2023
1 parent f0f5339 commit 1ac7d9a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/constants/meta_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:cliptopia/core/utils.dart';
class MetaInfo {
MetaInfo._();

static String get version => "v1.0.0+3";
static String get version => "v1.0.0+4-beta";
static String get daemonCompatibleVersion => "v0.0.3";
static const daemonDownloadUrl =
"https://github.com/omegaui/cliptopia_daemon/raw/master/cliptopia-daemon";
Expand Down
18 changes: 18 additions & 0 deletions lib/core/logger.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import 'dart:io';

import 'package:cliptopia/constants/meta_info.dart';
import 'package:cliptopia/core/argument_handler.dart';

enum DebugType { error, info, warning, url, response, statusCode }

final _sessionLog = File(MetaInfo.sessionLogFilePath);

void initSessionLog() {
if (_sessionLog.existsSync()) {
_sessionLog.deleteSync();
_sessionLog.writeAsStringSync(
"-----------------Logs of Cliptopia running in release mode-----------------\n",
flush: true);
_sessionLog.writeAsStringSync(">> Date: ${DateTime.now()}\n", flush: true);
}
}

prettyLog({
String? tag,
required dynamic value,
DebugType type = DebugType.info,
}) {
if (!ArgumentHandler.isDebugMode()) {
_sessionLog.writeAsStringSync(
"[${tag ?? "LOG"}] $value\n",
flush: true,
mode: FileMode.append,
);
return;
}
switch (type) {
Expand Down
4 changes: 0 additions & 4 deletions lib/core/search_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ class SearchEngine {

static final SearchWatcher primary = SearchWatcher(onEvent: (text) {
// this part will be reimplemented in search supported states
prettyLog(
value: "Search Engine switched to default",
type: DebugType.response,
);
});

SearchEngine() {
Expand Down
2 changes: 2 additions & 0 deletions lib/core/services/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import 'package:cliptopia/core/app_session.dart';
import 'package:cliptopia/core/clipboard_engine.dart';
import 'package:cliptopia/core/database/database.dart';
import 'package:cliptopia/core/database/exclusion_database.dart';
import 'package:cliptopia/core/logger.dart';
import 'package:cliptopia/core/search_engine.dart';
import 'package:cliptopia/core/services/route_service.dart';

class _InjectionContainer {
Set<dynamic> dependencies = {};

void put<T>(T t) {
prettyLog(value: "Added $T ...", tag: "DependencyInjector");
dependencies.add(t);
}

Expand Down
8 changes: 8 additions & 0 deletions lib/core/storage/storage.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:io';

import 'package:cliptopia/core/argument_handler.dart';
import 'package:cliptopia/core/logger.dart';
import 'package:cliptopia/core/storage/json_configurator.dart';
import 'package:cliptopia/core/utils.dart';
Expand All @@ -24,6 +25,13 @@ class Storage {
"Creating Cliptopia Cache Storage ...");
mkdir(combineHomePath(['.config', 'cliptopia', 'cache', 'images']),
"Creating Cliptopia Image Cache Storage ...");

// Initializing session logger ...
if (!ArgumentHandler.isDebugMode()) {
initSessionLog();
}

// Initializing preferences storage ...
_storage = JsonConfigurator(configName: 'app-settings.json');

// Writing Injector ...
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: The state-of-the-art clipboard manager.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+3
version: 1.0.0+4

environment:
sdk: '>=3.1.4 <4.0.0'
Expand Down

0 comments on commit 1ac7d9a

Please sign in to comment.