Skip to content

Commit

Permalink
3.18.4 Disabled logging to file by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigo Erit committed May 15, 2021
1 parent bccbcba commit 2b3cd2d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

| Operating System | Download |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Windows (32 and 64-bit) | <a href='https://github.com/MayGo/tockler/releases/download/v3.18.3/tockler-3.18.3-windows.exe'><img alt='Get it on Windows' width="134px" src='https://github.com/MayGo/tockler/raw/master/badges/BadgeWindows.png'/></a> |
| macOS | <a href='https://github.com/MayGo/tockler/releases/download/v3.18.3/Tockler-3.18.3.dmg'><img alt='Get it on macOS' width="134px" src='https://github.com/MayGo/tockler/raw/master/badges/BadgeMacOS.png'/></a> |
| Linux | <a href='https://github.com/MayGo/tockler/releases/download/v3.18.3/Tockler-3.18.3.AppImage'><img alt='Get it on Linux' width="134px" src='https://github.com/MayGo/tockler/raw/master/badges/BadgeLinux.png'/></a> |
| Windows (32 and 64-bit) | <a href='https://github.com/MayGo/tockler/releases/download/v3.18.4/tockler-3.18.4-windows.exe'><img alt='Get it on Windows' width="134px" src='https://github.com/MayGo/tockler/raw/master/badges/BadgeWindows.png'/></a> |
| macOS | <a href='https://github.com/MayGo/tockler/releases/download/v3.18.4/Tockler-3.18.4.dmg'><img alt='Get it on macOS' width="134px" src='https://github.com/MayGo/tockler/raw/master/badges/BadgeMacOS.png'/></a> |
| Linux | <a href='https://github.com/MayGo/tockler/releases/download/v3.18.4/Tockler-3.18.4.AppImage'><img alt='Get it on Linux' width="134px" src='https://github.com/MayGo/tockler/raw/master/badges/BadgeLinux.png'/></a> |

# Feedback

Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tockler",
"version": "3.18.3",
"version": "3.18.4",
"private": true,
"dependencies": {
"@analytics/google-analytics": "^0.5.2",
Expand Down
31 changes: 30 additions & 1 deletion client/src/components/Settings/AppForm.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
import { Card, Form, Switch } from 'antd';
import { Card, Form, Switch, Typography } from 'antd';
import React from 'react';
import {
getOpenAtLogin,
getIsAutoUpdateEnabled,
saveOpenAtLogin,
saveIsAutoUpdateEnabled,
getIsLoggingEnabled,
saveIsLoggingEnabled,
} from '../../services/settings.api';

const { Text } = Typography;

export const AppForm = () => {
const openAtLogin = getOpenAtLogin();
const isAutoUpdateEnabled = getIsAutoUpdateEnabled();
const isLoggingEnabled = getIsLoggingEnabled();
const onChangeOpenAtLogin = value => {
saveOpenAtLogin(value);
};

const onChangeAutoUpdate = value => {
saveIsAutoUpdateEnabled(value);
};
const onChangeLogging = value => {
saveIsLoggingEnabled(value);
};

const appName = process.env.REACT_APP_NAME;
const platform = (window as any).platform;

const linuxPath = `~/.config/${appName}/logs/main.log`;
const macOSPath = `~/Library/Logs/${appName}/main.log`;
const windowsPath = `%USERPROFILE%\\AppData\\Roaming\${appName}\\logs\\main.log`;

let logPath = linuxPath;
if (platform === 'win32') {
logPath = windowsPath;
} else if (platform === 'darwin') {
logPath = macOSPath;
}

return (
<Card title="App settings">
Expand All @@ -28,6 +50,13 @@ export const AppForm = () => {
<Switch defaultChecked={isAutoUpdateEnabled} onChange={onChangeAutoUpdate} /> {' '}
Auto update
</Form.Item>
<Form.Item>
<Switch defaultChecked={isLoggingEnabled} onChange={onChangeLogging} /> {' '}
Enable logging (Applies after restart)
<br />
<Text type="secondary">Log path: {logPath}</Text>
</Form.Item>
<Form.Item></Form.Item>
</Card>
);
};
13 changes: 13 additions & 0 deletions client/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
import { getIsLoggingEnabled } from './services/settings.api';

export const Logger: any = (window as any).logger;

const isProd = process.env.NODE_ENV === 'production';
Logger.transports.console.level = isProd ? 'warn' : 'debug';

let isLoggingEnabled = getIsLoggingEnabled();

if (isLoggingEnabled) {
Logger.transports.file.level = 'debug';
} else {
Logger.transports.file.level = false;
}
9 changes: 9 additions & 0 deletions client/src/services/settings.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export function getOpenAtLogin() {
export function getIsAutoUpdateEnabled() {
return config.get('isAutoUpdateEnabled') as boolean;
}
export function getIsLoggingEnabled() {
return config.get('isLoggingEnabled') as boolean;
}

export function saveOpenAtLogin(openAtLogin) {
if (openAtLogin !== getOpenAtLogin()) {
Expand All @@ -38,6 +41,12 @@ export function saveIsAutoUpdateEnabled(isAutoUpdateEnabled) {
config.set('isAutoUpdateEnabled', isAutoUpdateEnabled);
}
}
export function saveIsLoggingEnabled(isLoggingEnabled) {
if (isLoggingEnabled !== getIsLoggingEnabled()) {
Logger.debug('Setting isLoggingEnabled', isLoggingEnabled);
config.set('isLoggingEnabled', isLoggingEnabled);
}
}

export async function updateByName(name, jsonData) {
Logger.debug('updateByName', JSON.stringify(jsonData));
Expand Down
15 changes: 12 additions & 3 deletions electron/app/log-manager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as log from 'electron-log';
import * as Sentry from '@sentry/electron';
import { app } from 'electron';
import config from './config';

const version = app.getVersion();

if (process.env.NODE_ENV === 'production') {
const isProd = process.env.NODE_ENV === 'production';
if (isProd) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
Expand Down Expand Up @@ -46,8 +48,7 @@ const sentryTransportConsole = (msgObj) => {

(log as any).transports.console = sentryTransportConsole;

log.transports.console.level = 'debug';
log.transports.file.level = 'debug';
let isLoggingEnabled = config.persisted.get('isLoggingEnabled');

export class LogManager {
logger;
Expand All @@ -58,8 +59,16 @@ export class LogManager {

getLogger(name) {
const logObj = log.create(name);

log.transports.console.level = isProd ? 'warn' : 'debug';
(logObj as any).transports.console = sentryTransportConsole;

if (isLoggingEnabled) {
logObj.transports.file.level = 'debug';
} else {
logObj.transports.file.level = false;
}

return logObj;
}
}
Expand Down
4 changes: 2 additions & 2 deletions electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tockler",
"version": "3.18.3",
"version": "3.18.4",
"description": "Automatically track applications usage and working time",
"author": "Maigo Erit <[email protected]>",
"license": "GPL-2.0",
Expand Down Expand Up @@ -31,7 +31,7 @@
"eiphop": "^1.0.13",
"electron-context-menu": "2.3.0",
"electron-is-dev": "^1.2.0",
"electron-log": "^4.3.1",
"electron-log": "^4.3.5",
"electron-store": "6.0.1",
"electron-updater": "4.3.5",
"hazardous": "^0.3.0",
Expand Down
1 change: 1 addition & 0 deletions electron/preloadStuff.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ log.transports.console = sentryTransportConsole;
window.Sentry = Sentry;
window.version = version;
window.Store = Store;
window.platform = electron.remote.process.platform;
window.logger = log;
window.ipcRenderer = electron.ipcRenderer;

0 comments on commit 2b3cd2d

Please sign in to comment.