1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-23 23:47:57 +01:00

Merge pull request #113 from h3poteto/iss-101

closes #101 Add electron-log for production logger
This commit is contained in:
AkiraFukushima 2018-03-24 10:59:36 +09:00 committed by GitHub
commit 438bff9d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 9 deletions

5
package-lock.json generated
View File

@ -4409,6 +4409,11 @@
}
}
},
"electron-log": {
"version": "2.2.14",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-2.2.14.tgz",
"integrity": "sha512-Rj+XyK4nShe/nv9v1Uks4KEfjtQ6N+eSnx5CLpAjG6rlyUdAflyFHoybcHSLoq9l9pGavclULWS5IXgk8umc2g=="
},
"electron-osx-sign": {
"version": "0.4.8",
"resolved": "https://registry.npmjs.org/electron-osx-sign/-/electron-osx-sign-0.4.8.tgz",

View File

@ -61,6 +61,7 @@
},
"dependencies": {
"axios": "^0.18.0",
"electron-log": "^2.2.14",
"element-ui": "^2.2.1",
"google-fonts-webpack-plugin": "^0.4.4",
"is-empty": "^1.2.0",

View File

@ -1,4 +1,5 @@
import Mastodon from 'mastodon-api'
import log from 'electron-log'
const appName = 'whalebird'
const scope = 'read write follow'
@ -23,7 +24,7 @@ export default class Authentication {
getAuthorizationUrl (domain = 'mastodon.social') {
this.setOtherInstance(domain)
return Mastodon.createOAuthApp(this.baseURL + '/api/v1/apps', appName, scope)
.catch(err => console.error(err))
.catch(err => log.error(err))
.then((res) => {
this.clientId = res.client_id
this.clientSecret = res.client_secret

View File

@ -3,11 +3,18 @@
import { app, ipcMain, BrowserWindow, shell, Menu } from 'electron'
import Datastore from 'nedb'
import empty from 'is-empty'
import log from 'electron-log'
import Authentication from './auth'
import Account from './account'
import Streaming from './streaming'
/**
* Set log level
*/
log.transports.console.level = 'debug'
log.transports.file.level = 'info'
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
@ -198,11 +205,11 @@ let auth = new Authentication(db)
ipcMain.on('get-auth-url', (event, domain) => {
auth.getAuthorizationUrl(domain)
.catch((err) => {
console.error(err)
log.error(err)
event.sender.send('error-get-auth-url', err)
})
.then((url) => {
console.log(url)
log.debug(url)
event.sender.send('response-get-auth-url', url)
// Open authorize url in default browser.
shell.openExternal(url)
@ -212,7 +219,7 @@ ipcMain.on('get-auth-url', (event, domain) => {
ipcMain.on('get-access-token', (event, code) => {
auth.getAccessToken(code)
.catch((err) => {
console.error(err)
log.error(err)
event.sender.send('error-get-access-token', err)
})
.then((token) => {
@ -240,7 +247,7 @@ ipcMain.on('list-accounts', (event, _) => {
const account = new Account(db)
account.listAccounts()
.catch((err) => {
console.error(err)
log.error(err)
event.sender.send('error-list-accounts', err)
})
.then((accounts) => {
@ -252,6 +259,7 @@ ipcMain.on('get-local-account', (event, id) => {
const account = new Account(db)
account.getAccount(id)
.catch((err) => {
log.error(err)
event.sender.send('error-get-local-account', err)
})
.then((account) => {
@ -266,6 +274,7 @@ ipcMain.on('start-user-streaming', (event, ac) => {
const account = new Account(db)
account.getAccount(ac._id)
.catch((err) => {
log.error(err)
event.sender.send('error-start-user-streaming', err)
})
.then((account) => {
@ -284,6 +293,7 @@ ipcMain.on('start-user-streaming', (event, ac) => {
event.sender.send('notification-start-user-streaming', notification)
},
(err) => {
log.error(err)
event.sender.send('error-start-user-streaming', err)
}
)
@ -303,6 +313,7 @@ ipcMain.on('start-local-streaming', (event, ac) => {
const account = new Account(db)
account.getAccount(ac._id)
.catch((err) => {
log.error(err)
event.sender.send('error-start-local-streaming', err)
})
.then((account) => {
@ -319,6 +330,7 @@ ipcMain.on('start-local-streaming', (event, ac) => {
event.sender.send('update-start-local-streaming', update)
},
(err) => {
log.error(err)
event.sender.send('error-start-local-streaming', err)
}
)
@ -336,6 +348,7 @@ ipcMain.on('start-public-streaming', (event, ac) => {
const account = new Account(db)
account.getAccount(ac._id)
.catch((err) => {
log.error(err)
event.sender.send('error-start-public-streaming', err)
})
.then((account) => {
@ -352,6 +365,7 @@ ipcMain.on('start-public-streaming', (event, ac) => {
event.sender.send('update-start-public-streaming', update)
},
(err) => {
log.error(err)
event.sender.send('error-start-public-streaming', err)
}
)

View File

@ -1,4 +1,5 @@
import Mastodon from 'mastodon-api'
import log from 'electron-log'
export default class Streaming {
constructor (account) {
@ -14,7 +15,7 @@ export default class Streaming {
startUserStreaming (updateCallback, notificationCallback, errCallback) {
this.listener = this.client.stream('/streaming/user')
console.log('/streaming/user started')
log.info('/streaming/user started')
this.listener.on('message', (msg) => {
switch (msg.event) {
@ -25,7 +26,7 @@ export default class Streaming {
notificationCallback(msg.data)
break
default:
console.log(msg)
log.debug(msg)
break
}
})
@ -37,7 +38,7 @@ export default class Streaming {
start (path, updateCallback, errCallback) {
this.listener = this.client.stream(path)
console.log(`${path} started`)
log.info(`${path} started`)
this.listener.on('message', (msg) => {
switch (msg.event) {
@ -56,6 +57,6 @@ export default class Streaming {
stop () {
this.listener.stop()
console.log('streaming stopped')
log.info('streaming stopped')
}
}