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 { getAppLogPath, getServerLogPath } from './utils'
export const log = function (message: string) {
const appLogPath = getAppLogPath()
export const log = (message: string) => {
const path = getAppLogPath()
if (!message.startsWith('[')) {
message = `[APP]::${message}`
}
message = `${new Date().toISOString()} ${message}`
if (fs.existsSync(appLogPath)) {
var log_file = fs.createWriteStream(appLogPath, {
flags: 'a',
})
log_file.write(util.format(message) + '\n')
log_file.close()
console.debug(message)
}
writeLog(message, path)
}
export const logServer = function (message: string) {
const serverLogPath = getServerLogPath()
export const logServer = (message: string) => {
const path = getServerLogPath()
if (!message.startsWith('[')) {
message = `[SERVER]::${message}`
}
message = `${new Date().toISOString()} ${message}`
writeLog(message, path)
}
if (fs.existsSync(serverLogPath)) {
var log_file = fs.createWriteStream(serverLogPath, {
const writeLog = (message: string, logPath: string) => {
if (!fs.existsSync(logPath)) {
fs.writeFileSync(logPath, message)
} else {
const logFile = fs.createWriteStream(logPath, {
flags: 'a',
})
log_file.write(util.format(message) + '\n')
log_file.close()
logFile.write(util.format(message) + '\n')
logFile.close()
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 { 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 function useVaultDirectory() {
const [isSameDirectory, setIsSameDirectory] = useAtom(isSameDirectoryAtom)
const { setMainViewState } = useMainViewState()
const [isDirectoryConfirm, setIsDirectoryConfirm] = useAtom(
isDirectoryConfirmAtom
)
const [isErrorSetNewDest, setIsErrorSetNewDest] = useAtom(
isErrorSetNewDestAtom
)
const [currentPath, setCurrentPath] = useAtom(currentPathAtom)
const [newDestinationPath, setNewDestinationPath] = useAtom(
newDestinationPathAtom
)
const [isSameDirectory, setIsSameDirectory] = useState(false)
const [isDirectoryConfirm, setIsDirectoryConfirm] = useState(false)
const [isErrorSetNewDest, setIsErrorSetNewDest] = useState(false)
const [currentPath, setCurrentPath] = useState('')
const [newDestinationPath, setNewDestinationPath] = useState('')
useEffect(() => {
window.core?.api
@ -34,7 +17,6 @@ export function useVaultDirectory() {
?.then((appConfig: AppConfiguration) => {
setCurrentPath(appConfig.data_folder)
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const setNewDestination = async () => {