-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46b06e2
commit 11a98b0
Showing
9 changed files
with
534 additions
and
24,172 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-disable no-console */ | ||
(() => { | ||
const _log = console.log; | ||
const _error = console.error; | ||
const _warning = console.warning; | ||
|
||
console.error = function(errMessage) { | ||
_error.apply(console, arguments); | ||
}; | ||
|
||
console.log = function(logMessage) { | ||
// Do something with the log message | ||
_log.apply(console, arguments); | ||
}; | ||
|
||
console.warning = function(warnMessage) { | ||
// do something with the warn message | ||
_warning.apply(console, arguments); | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import axios from "axios"; | ||
import { createLogger } from "redux-logger"; | ||
import { store } from "./../index"; | ||
|
||
// const api = new Api(); | ||
// api.setAuthorizationHeader( | ||
// "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJyb290IiwiYWRkcmVzcyI6IjEzcHBYMnNpQTNNWHRBZDdCS0pFeFR6dGNOZFI5OVRIQjZib2FnIiwib3JnYW5pemF0aW9uIjoiS2ZXIiwib3JnYW5pemF0aW9uQWRkcmVzcyI6IjEzcHBYMnNpQTNNWHRBZDdCS0pFeFR6dGNOZFI5OVRIQjZib2FnIiwiZ3JvdXBzIjpbXSwiaWF0IjoxNjM0Nzk0MjY1LCJleHAiOjE2MzQ4MjMwNjV9.aH4BUpofN2oFt9L9_3zIBQ7QNxJLrHL5fXcKf7Ha0-8" | ||
// ); | ||
let instance = undefined; | ||
const getToken = () => (store ? store.getState().toJS().login.jwt : ""); | ||
const getUserId = () => "todo"; | ||
|
||
const createConnection = () => { | ||
//if url provided && url is https when not in dev mode | ||
instance = axios.create(); | ||
instance.defaults.baseURL = `http://localhost:3001`; | ||
}; | ||
|
||
const setToken = () => { | ||
let t = getToken(); | ||
instance.defaults.headers.common["Authorization"] = t ? `Bearer ${t}` : ""; | ||
}; | ||
|
||
const logger = createLogger({ | ||
timestamp: true, | ||
logErrors: true, | ||
predicate: (getState, action) => predicate(getState, action), | ||
stateTransformer: s => stateTransformer(s), | ||
diff: true, | ||
errorTransformer: error => errorTransformer(error) | ||
}); | ||
const stateTransformer = s => s; | ||
|
||
const predicate = (getState, action) => { | ||
createLogMsg({ | ||
service: "FRONTEND", | ||
what: "Error", //todo: this should be trace | ||
why: { | ||
action: action, | ||
prevState: stateTransformer(getState()) | ||
} | ||
}); | ||
//if (process.env.loglevel == "trace") return true; | ||
return false; | ||
}; | ||
|
||
const errorTransformer = error => { | ||
createLogMsg({ | ||
service: "FRONTEND", | ||
what: "Error", | ||
why: error | ||
}); | ||
return error; | ||
}; | ||
|
||
export const createLogMsg = async log => { | ||
const msg = { | ||
...log, | ||
when: new Date().toString(), | ||
who: getUserId() | ||
}; | ||
if (instance) { | ||
if ( | ||
instance.defaults.headers.common["Authorization"] === "" || | ||
instance.defaults.headers.common["Authorization"] === undefined | ||
) | ||
setToken(); | ||
instance.post("/api", { ...msg }); | ||
} | ||
}; | ||
|
||
createConnection(); | ||
export default logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.