Skip to content

Commit

Permalink
Using the Datadog API directlyfor the logging.
Browse files Browse the repository at this point in the history
Removed the use of the ELK logging.
Fixed the double topbar that caused to log twice every navigation. The MainPage is not neccesary anymore.
  • Loading branch information
alcastrob committed May 23, 2020
1 parent 6290129 commit cb4379a
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 410 deletions.
50 changes: 2 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 9 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "labmanager",
"version": "1.0.21",
"author": "Angel Castro <al.castro@gmail.com>",
"version": "1.0.22",
"author": "Angel Castro <me@angelcastro.info>",
"description": "An application for managing a dental prosthetic laboratory",
"license": "MIT",
"main": "./dist/electron/main.js",
Expand Down Expand Up @@ -31,8 +31,7 @@
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"contents": [{
"x": 410,
"y": 150,
"type": "link",
Expand All @@ -54,16 +53,13 @@
"linux": {
"icon": "build/icons"
},
"publish": [
{
"provider": "github",
"owner": "alcastrob",
"repo": "labManager"
}
]
"publish": [{
"provider": "github",
"owner": "alcastrob",
"repo": "labManager"
}]
},
"dependencies": {
"@datadog/browser-logs": "^1.6.3",
"axios": "^0.18.0",
"better-sqlite3": "^5.4.0",
"bluebird": "^3.5.3",
Expand Down Expand Up @@ -174,4 +170,4 @@
"webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.3"
}
}
}
2 changes: 1 addition & 1 deletion secrets_sample.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default Object.freeze({
datadogClientToken: '',
datadogApiToken: '',
logstashUrl: ''
})
85 changes: 17 additions & 68 deletions src/main/log-helper.Datadog.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,27 @@
import {
datadogLogs
} from '@datadog/browser-logs'
import axios from 'axios'
import secrets from '../../secrets'

export function remoteLogDatadog(logger, options) {
export async function remoteLogDatadog(logger) {
try {
if (!logger || !logger.methodFactory) {
throw new Error('loglevel instance has to be specified in order to be extended')
}

var _logger = logger
var _callOriginal = (options && options.callOriginal) || false
var _originalFactory = _logger.methodFactory

logger.methodFactory = function (methodName, logLevel) {
var rawMethod = _originalFactory(methodName, logLevel)

var payload = {
clientTimestamp: new Date().toISOString(),
host: options.host,
version: options.version,
system: options.system
}
switch (methodName) {
case 'trace':
case 'debug':
return function (message) {
try {
datadogLogs.logger.debug(message, payload)

if (_callOriginal) {
rawMethod(options)
}
} catch (err) {
console.log('Error: ', err)
}
}
case 'info':
return function (message) {
try {
datadogLogs.logger.info(message, payload)

if (_callOriginal) {
rawMethod(options)
}
} catch (err) {
console.log('Error: ', err)
}
}
case 'warn':
return function (message) {
try {
datadogLogs.logger.warn(message, payload)

if (_callOriginal) {
rawMethod(options)
}
} catch (err) {
console.log('Error: ', err)
}
}
case 'error':
return function (message) {
try {
datadogLogs.logger.error(message, payload)

if (_callOriginal) {
rawMethod(options)
}
} catch (err) {
console.log('Error: ', err)
}
}
default:
console.log(`LogLevel not supported: ${methodName}`)
return function (message) {
var payload = {
message: message,
status: methodName,
host: require('os').hostname(),
version: require('../../package.json').version,
system: 'labManager'
}

axios.post(`https://http-intake.logs.datadoghq.eu/v1/input/${secrets.datadogApiToken}`, payload).catch(error => {
console.error('Failed to call to datadog with this payload', payload)
console.error(error)
throw error
})
}
}
} catch (err) {
Expand Down
Loading

0 comments on commit cb4379a

Please sign in to comment.