make logger optional so code can be re-used for CLI interface

This commit is contained in:
Ondřej Synáček 2020-07-14 22:07:42 +02:00
parent bf36383bff
commit 59eb0191bf
4 changed files with 27 additions and 21 deletions

View File

@ -5,12 +5,9 @@ const parseUsingDOM = require('./services/dom-parser')
const { createParserError, createAppLogger } = require('./utils')
const parseHTMLString = (html, { verbose }) => {
const dev = process.env.NODE_ENV === 'development'
const logger = createAppLogger({ dev })
if (!verbose) {
logger.transports.forEach((transport) => (transport.silent = true))
}
const logger = verbose ?
createAppLogger({ dev: true }) :
null
try {
const LDJSONEventData = parseUsingLDJSONData(html, { logger })

View File

@ -1,11 +1,14 @@
const request = require('request')
const crawl = async (url, { logger }) => {
logger.log({
message: `Crawl started for url: ${url}`,
level: 'info',
service: 'parser',
})
if (logger) {
logger.log({
message: `Crawl started for url: ${url}`,
level: 'info',
service: 'parser',
})
}
return new Promise((resolve, reject) => {
request({
url,

View File

@ -37,11 +37,14 @@ const createLocationData = (streetText, areaText) => {
// NOTE: Fallback parser
// Attempt reading event data directly from DOM
const parseUsingDOM = (html, url, { logger }) => {
logger.log({
message: 'Using fallback DOM parser',
level: 'info',
service: 'parser',
})
if (logger) {
logger.log({
message: 'Using fallback DOM parser',
level: 'info',
service: 'parser',
})
}
const $ = cheerio.load(html)
const title = $('title').text()

View File

@ -38,11 +38,14 @@ const parseEventData = (eventData) => {
}
const parseUsingLDJSONData = (html, { logger }) => {
logger.log({
message: 'Parsing using LDJSON parser',
level: 'info',
service: 'parser',
})
if (logger) {
logger.log({
message: 'Parsing using LDJSON parser',
level: 'info',
service: 'parser',
})
}
try {
// NOTE: Mobile web should have serialized
// event info in one of the script tags