-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚛️📝 Log only using electron-log (#96)
* ⚛️📝 Log only using electron-log * v3.3.20
- Loading branch information
1 parent
c7e45d0
commit 9f0572a
Showing
18 changed files
with
130 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { app } from 'electron'; | ||
|
||
export const DOWNLOADS_PATH = app.getPath('downloads'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import path from 'path'; | ||
|
||
import { app } from 'electron'; | ||
|
||
export const MAIN_LOG_FILENAME = 'main.log'; | ||
|
||
let LOGS_PATH: string; | ||
let MAIN_LOG_FILE_PATH: string; | ||
|
||
if (app && app.getPath) { | ||
LOGS_PATH = app.getPath('logs'); | ||
MAIN_LOG_FILE_PATH = path.join(LOGS_PATH, MAIN_LOG_FILENAME); | ||
} else { | ||
// app is undefined in renderer process | ||
LOGS_PATH = ''; | ||
MAIN_LOG_FILE_PATH = MAIN_LOG_FILENAME; | ||
} | ||
|
||
export { LOGS_PATH, MAIN_LOG_FILE_PATH }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import path from 'path'; | ||
|
||
import { shell } from 'electron'; | ||
|
||
import { DOWNLOADS_PATH } from '../downloads/constants'; | ||
import { copyFile } from '../main-process/copy-file'; | ||
|
||
import { | ||
MAIN_LOG_FILE_PATH, | ||
} from './constants'; | ||
|
||
const DESKTOP_APP_MAIN_LOG_FILENAME = 'loadmill-desktop-app.log'; | ||
export const APP_LOG_SAVE_PATH = path.join(DOWNLOADS_PATH, DESKTOP_APP_MAIN_LOG_FILENAME); | ||
|
||
export const downloadMainLog = (): void => { | ||
copyFile(MAIN_LOG_FILE_PATH, APP_LOG_SAVE_PATH, () => { | ||
shell.showItemInFolder(APP_LOG_SAVE_PATH); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
import path from 'path'; | ||
|
||
import log from 'electron-log'; | ||
|
||
const setLogLevels = () => { | ||
import { | ||
LOGS_PATH, | ||
} from './constants'; | ||
|
||
const setMainLogLevels = () => { | ||
log.transports.file.level = 'info'; | ||
log.transports.console.level = 'silly'; | ||
// Now log.debug Will show in console mode (dev) but not in file mode (prod) | ||
}; | ||
|
||
setLogLevels(); | ||
setMainLogLevels(); | ||
|
||
log.info('Main logger created. Writing to file: ', log.transports.file.getFile().path); | ||
|
||
export const createLogger = ( | ||
logId: string, | ||
filePath: string, | ||
fileLevel: log.LevelOption = 'info', | ||
consoleLevel: log.LevelOption = 'silly', | ||
): Logger => { | ||
const logger = log.create(logId) as Logger; | ||
logger.transports.file.resolvePath = () => path.join(LOGS_PATH, filePath); | ||
logger.transports.file.level = fileLevel; | ||
logger.transports.console.level = consoleLevel; | ||
logger.filePath = logger.transports.file.getFile().path; | ||
return logger; | ||
}; | ||
|
||
export type Logger = log.ElectronLog & { | ||
filePath: string; | ||
}; | ||
|
||
export default log; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import log, { createLogger } from '../../log'; | ||
|
||
const AGENT_LOG_FILENAME = 'agent.log'; | ||
const AGENT_LOGGER_NAME = 'agent-logger'; | ||
|
||
export const agentLogger = createLogger( | ||
AGENT_LOGGER_NAME, | ||
AGENT_LOG_FILENAME, | ||
'info', | ||
false, | ||
); | ||
|
||
log.info( | ||
'Agent logger created. Writing to file: ', | ||
agentLogger.filePath, | ||
); | ||
|
||
export const agentLoggerFilePath = agentLogger.filePath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import path from 'path'; | ||
|
||
import { shell } from 'electron'; | ||
|
||
import { DOWNLOADS_PATH } from '../../downloads/constants'; | ||
import { | ||
DOWNLOAD_AGENT_LOG, | ||
} from '../../universal/constants'; | ||
import { | ||
AGENT_LOG_SAVE_PATH, | ||
FULL_AGENT_LOG_PATH, | ||
} from '../constants'; | ||
import { copyFile } from '../copy-file'; | ||
import { subscribeToMainProcessMessage } from '../main-events'; | ||
|
||
import { agentLoggerFilePath } from './agent-logger'; | ||
|
||
const AGENT_LOG_FILENAME = 'loadmill-private-agent.log'; | ||
export const agentLogDownloadLocation = path.join(DOWNLOADS_PATH, AGENT_LOG_FILENAME); | ||
|
||
export const subscribeToDownloadAgentLog = (): void => { | ||
subscribeToMainProcessMessage(DOWNLOAD_AGENT_LOG, downloadAgentLog); | ||
}; | ||
|
||
const downloadAgentLog = (): void => { | ||
copyFile(FULL_AGENT_LOG_PATH, AGENT_LOG_SAVE_PATH, () => { | ||
shell.showItemInFolder(AGENT_LOG_SAVE_PATH); | ||
copyFile(agentLoggerFilePath, agentLogDownloadLocation, () => { | ||
shell.showItemInFolder(agentLogDownloadLocation); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import path from 'path'; | ||
|
||
import { app } from 'electron'; | ||
|
||
export const PROXY_CERTIFICATES_DIR_PATH = path.join(app.getPath('userData'), 'proxy'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
import path from 'path'; | ||
|
||
import { shell } from 'electron'; | ||
|
||
import { DOWNLOADS_PATH } from '../../downloads/constants'; | ||
import { | ||
sendFromProxyToRenderer, | ||
} from '../../inter-process-communication/proxy-to-render'; | ||
import { | ||
DOWNLOAD_CERTIFICATE, | ||
DOWNLOADED_CERTIFICATE_SUCCESS, | ||
} from '../../universal/constants'; | ||
import { | ||
PROXY_CERTIFICATE_PATH, | ||
PROXY_CERTIFICATE_SAVE_PATH, | ||
} from '../constants'; | ||
import { copyFile } from '../copy-file'; | ||
import { subscribeToMainProcessMessage } from '../main-events'; | ||
|
||
import { | ||
PROXY_CERTIFICATES_DIR_PATH, | ||
} from './constants'; | ||
|
||
export const proxyCertificatePath = path.join(PROXY_CERTIFICATES_DIR_PATH, 'certs', 'ca.pem'); | ||
export const proxyCertificateDownloadLocation = path.join(DOWNLOADS_PATH, 'loadmill-proxy-certificate.pem'); | ||
|
||
export const subscribeToDownloadCertificate = (): void => { | ||
subscribeToMainProcessMessage(DOWNLOAD_CERTIFICATE, downloadCertificate); | ||
}; | ||
|
||
const downloadCertificate = (): void => { | ||
copyFile(PROXY_CERTIFICATE_PATH, PROXY_CERTIFICATE_SAVE_PATH, () => { | ||
copyFile(proxyCertificatePath, proxyCertificateDownloadLocation, () => { | ||
sendFromProxyToRenderer({ type: DOWNLOADED_CERTIFICATE_SUCCESS }); | ||
shell.showItemInFolder(PROXY_CERTIFICATE_SAVE_PATH); | ||
shell.showItemInFolder(proxyCertificateDownloadLocation); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.