From 66647f69f654a189f737ca1f31c4c11960c42d04 Mon Sep 17 00:00:00 2001 From: sienori Date: Thu, 22 Aug 2019 14:48:14 +0900 Subject: [PATCH] Add logs to popup page --- src/popup/components/PopupPage.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/popup/components/PopupPage.js b/src/popup/components/PopupPage.js index dad1570..83c4370 100644 --- a/src/popup/components/PopupPage.js +++ b/src/popup/components/PopupPage.js @@ -1,5 +1,6 @@ import React, { Component } from "react"; import browser from "webextension-polyfill"; +import log from "loglevel"; import { initSettings, getSettings } from "src/settings/settings"; import { updateLogLevel, overWriteLogLevel } from "src/common/log"; import translate from "src/common/translate"; @@ -9,6 +10,8 @@ import ResultArea from "./ResultArea"; import Footer from "./Footer"; import "../styles/PopupPage.scss"; +const logDir = "popup/PopupPage"; + const getTabInfo = async () => { try { const tab = (await browser.tabs.query({ currentWindow: true, active: true }))[0]; @@ -64,6 +67,7 @@ export default class PopupPage extends Component { }; handleInputText = inputText => { + log.log(logDir, "handleInputText()", inputText); this.setState({ inputText: inputText }); const waitTime = getSettings("waitTime"); @@ -75,12 +79,14 @@ export default class PopupPage extends Component { }; handleLangChange = lang => { + log.info(logDir, "handleLangChange()", lang); this.setState({ targetLang: lang }); const inputText = this.state.inputText; if (inputText !== "") this.translateText(inputText, lang); }; translateText = async (text, targetLang) => { + log.info(logDir, "translateText()", text, targetLang); const result = await translate(text, "auto", targetLang); this.setState({ resultText: result.resultText, @@ -104,11 +110,13 @@ export default class PopupPage extends Component { if (!this.isSwitchedSecondLang) { if (equalsSourceAndTarget && equalsSourceAndDefault) { + log.info(logDir, "=>switchSecondLang()", result, secondLang); this.handleLangChange(secondLang); this.isSwitchedSecondLang = true; } } else { if (!equalsSourceAndDefault) { + log.info(logDir, "=>switchSecondLang()", result, defaultTargetLang); this.handleLangChange(defaultTargetLang); this.isSwitchedSecondLang = false; }