fix: app log not being printed (#1790)

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
This commit is contained in:
NamH 2024-01-25 22:29:27 +07:00 committed by GitHub
parent 7ed523e183
commit b2ff76ce80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 40 deletions

View File

@ -2,38 +2,36 @@ import fs from 'fs'
import util from 'util' import util from 'util'
import { getAppLogPath, getServerLogPath } from './utils' import { getAppLogPath, getServerLogPath } from './utils'
export const log = function (message: string) { export const log = (message: string) => {
const appLogPath = getAppLogPath() const path = getAppLogPath()
if (!message.startsWith('[')) { if (!message.startsWith('[')) {
message = `[APP]::${message}` message = `[APP]::${message}`
} }
message = `${new Date().toISOString()} ${message}` message = `${new Date().toISOString()} ${message}`
if (fs.existsSync(appLogPath)) { writeLog(message, path)
var log_file = fs.createWriteStream(appLogPath, {
flags: 'a',
})
log_file.write(util.format(message) + '\n')
log_file.close()
console.debug(message)
}
} }
export const logServer = function (message: string) { export const logServer = (message: string) => {
const serverLogPath = getServerLogPath() const path = getServerLogPath()
if (!message.startsWith('[')) { if (!message.startsWith('[')) {
message = `[SERVER]::${message}` message = `[SERVER]::${message}`
} }
message = `${new Date().toISOString()} ${message}` message = `${new Date().toISOString()} ${message}`
writeLog(message, path)
}
if (fs.existsSync(serverLogPath)) { const writeLog = (message: string, logPath: string) => {
var log_file = fs.createWriteStream(serverLogPath, { if (!fs.existsSync(logPath)) {
fs.writeFileSync(logPath, message)
} else {
const logFile = fs.createWriteStream(logPath, {
flags: 'a', flags: 'a',
}) })
log_file.write(util.format(message) + '\n') logFile.write(util.format(message) + '\n')
log_file.close() logFile.close()
console.debug(message) console.debug(message)
} }
} }

View File

@ -1,32 +1,15 @@
import { useEffect } from 'react' import { useEffect, useState } from 'react'
import { fs, AppConfiguration } from '@janhq/core' import { fs, AppConfiguration } from '@janhq/core'
import { atom, useAtom } from 'jotai'
import { useMainViewState } from './useMainViewState'
const isSameDirectoryAtom = atom(false)
const isDirectoryConfirmAtom = atom(false)
const isErrorSetNewDestAtom = atom(false)
const currentPathAtom = atom('')
const newDestinationPathAtom = atom('')
export const SUCCESS_SET_NEW_DESTINATION = 'successSetNewDestination' export const SUCCESS_SET_NEW_DESTINATION = 'successSetNewDestination'
export function useVaultDirectory() { export function useVaultDirectory() {
const [isSameDirectory, setIsSameDirectory] = useAtom(isSameDirectoryAtom) const [isSameDirectory, setIsSameDirectory] = useState(false)
const { setMainViewState } = useMainViewState() const [isDirectoryConfirm, setIsDirectoryConfirm] = useState(false)
const [isDirectoryConfirm, setIsDirectoryConfirm] = useAtom( const [isErrorSetNewDest, setIsErrorSetNewDest] = useState(false)
isDirectoryConfirmAtom const [currentPath, setCurrentPath] = useState('')
) const [newDestinationPath, setNewDestinationPath] = useState('')
const [isErrorSetNewDest, setIsErrorSetNewDest] = useAtom(
isErrorSetNewDestAtom
)
const [currentPath, setCurrentPath] = useAtom(currentPathAtom)
const [newDestinationPath, setNewDestinationPath] = useAtom(
newDestinationPathAtom
)
useEffect(() => { useEffect(() => {
window.core?.api window.core?.api
@ -34,7 +17,6 @@ export function useVaultDirectory() {
?.then((appConfig: AppConfiguration) => { ?.then((appConfig: AppConfiguration) => {
setCurrentPath(appConfig.data_folder) setCurrentPath(appConfig.data_folder)
}) })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])
const setNewDestination = async () => { const setNewDestination = async () => {