Skip to content

Commit

Permalink
create self-handled logger
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Nov 15, 2023
1 parent 5bc6244 commit 384bcac
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/api/apis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import api from "../api/config";
import { UpdateInfo } from "../states/app";
import { mapAPIResponseServerListToAppStructure } from "../utils/helpers";
import { Log } from "../utils/logger";
import { APIResponseServer, Server } from "../utils/types";

export const getCachedList = async () => {
Expand All @@ -15,7 +16,7 @@ export const getCachedList = async () => {
}
})
.catch((e) => {
console.log(e);
Log.debug(e);
resolve({ success: false, servers: [] });
});
});
Expand All @@ -30,7 +31,7 @@ export const getUpdateInfo = async () => {
resolve({ success: true, info: response.data });
})
.catch((e) => {
console.log(e);
Log.debug(e);
resolve({ success: false, info: undefined });
});
}
Expand Down
1 change: 0 additions & 1 deletion src/containers/MainBody/ServerList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const ServerItem = memo((props: IProps) => {
onPress={() => onPress()}
// @ts-ignore
onContextMenu={(e) => {
console.log(e);
e.preventDefault();
showContextMenu({ x: e.clientX, y: e.clientY }, server);
return e;
Expand Down
3 changes: 2 additions & 1 deletion src/containers/Settings/Tab/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { usePersistentServers } from "../../../states/servers";
import { useSettings } from "../../../states/settings";
import { checkDirectoryValidity } from "../../../utils/helpers";
import { Server } from "../../../utils/types";
import { Log } from "../../../utils/logger";

const General = () => {
const { hostOS } = useAppState();
Expand Down Expand Up @@ -45,7 +46,7 @@ const General = () => {
setNickName(name);
}
} catch (e) {
console.log(e);
Log.debug(e);
}
};

Expand Down
16 changes: 16 additions & 0 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { process } from "@tauri-apps/api";

export namespace Log {
export const info = (message?: any, ...optionalParams: any[]) => {
console.log(message, ...optionalParams);
};

export const debug = (message?: any, ...optionalParams: any[]) => {
try {
// @ts-ignore
if (process && process.env.NODE_ENV === "development") {
console.log(message, ...optionalParams);
}
} catch (e) {}
};
}

0 comments on commit 384bcac

Please sign in to comment.