Skip to content

Commit

Permalink
console log levels; disabled in --production
Browse files Browse the repository at this point in the history
  • Loading branch information
awatson1978 committed Jan 21, 2023
1 parent 69b98de commit 4b716b1
Show file tree
Hide file tree
Showing 38 changed files with 478 additions and 169 deletions.
172 changes: 147 additions & 25 deletions app/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import { Meteor } from 'meteor/meteor';
import "setimmediate";


// some functions that do log level filtering
const LEVEL = Symbol.for('level');
function filterOnly(level) {
return format(function (info) {
if (info[LEVEL] === level) {
return info;
}
})();
}
// some functions that do log level filtering
const LEVEL = Symbol.for('level');
function filterOnly(level) {
return format(function (info) {
if (info[LEVEL] === level) {
return info;
}
})();
}

function hideDataLogLevel() {
return format(function (info) {
if (info[LEVEL] !== 'data') {
return info;
}
})();
}
function hideDataLogLevel() {
return format(function (info) {
if (info[LEVEL] !== 'data') {
return info;
}
})();
}

function onlyDisplayDataLogLevel() {
return format(function (info) {
if (info[LEVEL] === 'data') {
return info;
}
})();
}
function onlyDisplayDataLogLevel() {
return format(function (info) {
if (info[LEVEL] === 'data') {
return info;
}
})();
}


// lets create a global logger
Expand Down Expand Up @@ -89,7 +89,7 @@ addColors({
});

// what is the logging threshold set in the Meteor.settings file?
logger.verbose('Setting the logging threshold to: ' + get(Meteor, 'settings.public.loggingThreshold'))
console.info('Setting the logging threshold to: ' + get(Meteor, 'settings.public.loggingThreshold'))


// introspection for the win
Expand All @@ -111,4 +111,126 @@ if(Meteor.isClient){
window.logger = logger;
}

export default logger;

export function log() {
console.log('biz')

/* jshint -W021 */
//if(typeof window !== "undefined"){

// let log;
if (window.console) {

// Only run on the first time through - reset this function to the appropriate console.log helper
if (Function.prototype.bind) {
log = Function.prototype.bind.call(console.log, console);
} else {
log = function() { Function.prototype.apply.call(console.log, console, arguments); };
}

// console.info('log.log', log);
console.log('log.arguments[0]', arguments[0]);
log.apply(this, arguments);
}
//}
}


//Then redefine the old console
if(typeof window === "object"){
window.console = console;
window.log = log;
}


export const message = {
log: function(text){
if(['everything'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
console.log('message.log', log)
console.log('log.arguments[0]', arguments[0])
}
if(['everything', 'debug', 'info', 'warn', 'verbose'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
if (Function.prototype.bind) {
log = Function.prototype.bind.call(console.log, console);
}
else {
log = function() {
Function.prototype.apply.call(console.log, console, arguments);
};
}
log.apply(this, arguments);
}
// Your code
},
info: function (text) {
if(['everything'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
console.log('info.arguments[0]', arguments[0])
}
if(['everything', 'debug', 'info', 'warn', 'verbose'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
if (Function.prototype.bind) {
log = Function.prototype.bind.call(console.log, console);
}
else {
log = function() {
Function.prototype.apply.call(console.log, console, arguments);
};
}
log.apply(this, arguments);
}
},
debug: function (text) {
if(['everything'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
console.log('debug.arguments[0]', arguments[0])
}
if(['everything', 'debug', 'info', 'warn', 'verbose'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
if (Function.prototype.bind) {
log = Function.prototype.bind.call(console.log, console);
}
else {
log = function() {
Function.prototype.apply.call(console.log, console, arguments);
};
}
log.apply(this, arguments);
}
},
warn: function (text) {
if(['everything'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
console.log('warn.arguments[0]', arguments[0])
}
if(['everything', 'debug', 'info', 'warn', 'verbose'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
if (Function.prototype.bind) {
log = Function.prototype.bind.call(console.log, console);
}
else {
log = function() {
Function.prototype.apply.call(console.log, console, arguments);
};
}
log.apply(this, arguments);
}
},
error: function (text) {
if(['everything'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
console.error('error.arguments[0]', arguments[0])
}
if(['everything', 'debug', 'info', 'warn', 'verbose'].includes(get(Meteor, 'settings.public.loggingThreshold'))){
if (Function.prototype.bind) {
log = Function.prototype.bind.call(console.log, console);
}
else {
log = function() {
Function.prototype.apply.call(console.log, console, arguments);
};
}
log.apply(this, arguments);
}
}
}
// //Then redefine the old console
// if(typeof window === "object"){
// window.console = message;
// }


export default { logger, log, message };
7 changes: 4 additions & 3 deletions app/WebsocketSubscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BaseSchema, DomainResourceSchema } from 'meteor/clinical:hl7-resource-d
import { InboundRequests, UdapCertificates, OAuthClients } from 'meteor/clinical:hl7-fhir-data-infrastructure';

import base64url from 'base64-url';
import { message } from './Logger';

import {
FhirUtilities,
Expand Down Expand Up @@ -173,7 +174,7 @@ function setCollectionDefaultQuery(collectionName, subscriptionRecord){
if(get(subscriptionRecord, 'criteria')){
let criteriaString = get(subscriptionRecord, 'criteria');
let criteriaJson = JSON.parse(criteriaString);
console.log('criteriaJson', criteriaJson);
message.trace('criteriaJson', criteriaJson);

if(typeof criteriaJson === "object"){
Object.assign(defaultQuery, criteriaJson);
Expand All @@ -190,7 +191,7 @@ Meteor.startup(function(){

// should we iterate through Meteor.settings.private.fhir.rest here?
Object.keys(Collections).forEach(function(collectionName){
console.log("Autosubscribing to the " + collectionName + " data channel.")
console.info("Autosubscribing to the " + collectionName + " data channel.")
Meteor.subscribe(collectionName);
});
}
Expand All @@ -200,7 +201,7 @@ Meteor.startup(function(){
// subscribe to a DDS pubsub based on the FHIR Subscription record
console.log("Subscriptions count: " + Subscriptions.find().count())
Subscriptions.find().forEach(function(subscriptionRecord){
console.log("Subscribing to " + collectionName + " DDP cursor.");
console.info("Subscribing to " + collectionName + " DDP cursor.");
Meteor.subscribe(get(subscriptionRecord, 'channel.endpoint'));
});
}
Expand Down
6 changes: 3 additions & 3 deletions app/accounts/Accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Session } from 'meteor/session';
import jwt from 'jsonwebtoken';

let apiHostFromSettings = get(Meteor, 'settings.public.interfaces.accountsServer.host') + ":" + get(Meteor, 'settings.public.interfaces.accountsServer.port');
console.log('Accounts.apiHost', apiHostFromSettings);
// console.log('Accounts.apiHost', apiHostFromSettings);

const accountsRest = new RestClient({
apiHost: apiHostFromSettings,
Expand All @@ -31,10 +31,10 @@ Meteor.startup(async function(){
try {
if(typeof(Storage) !== "undefined"){
let tokens = await accountsClient.getTokens();
console.log('tokens', tokens)
// console.log('tokens', tokens)
if(get(tokens, 'accessToken')){
let decoded = jwt.decode(tokens.accessToken, {complete: true});
console.log('decoded', decoded)
// console.log('decoded', decoded)
Session.set('accountsAccessToken', get(tokens, 'accessToken'))
Session.set('accountsRefreshToken', get(tokens, 'refreshToken'))
}
Expand Down
8 changes: 4 additions & 4 deletions app/accounts/AuthContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ async function fetchUser(setAuthContextState){
};

async function loginWithService(service, credentials, setError, setSuccess){
console.log('AuthContext.loginWithService()', service, credentials);
// console.log('AuthContext.loginWithService()', service, credentials);

let loginResponse;

try {
loginResponse = await accountsClient.loginWithService(service, credentials);
console.log('AuthContext.loginResponse', loginResponse)
// console.log('AuthContext.loginResponse', loginResponse)

if(typeof setSuccess === "function"){
setSuccess(loginResponse);
Expand All @@ -95,7 +95,7 @@ async function loginWithService(service, credentials, setError, setSuccess){
}

if (error instanceof AccountsJsError) {
console.log('error.message', error.message)
console.error('error.message', error.message)

// You can access the error message via `error.message`
// Eg: "Email already exists"
Expand All @@ -117,7 +117,7 @@ async function loginWithService(service, credentials, setError, setSuccess){
}

if(Meteor.isClient && loginResponse){
console.log('loginResponse', loginResponse);
// console.log('loginResponse', loginResponse);
Session.set('currentUser', get(loginResponse, 'user'));
Session.set('selectedPatientId', get(loginResponse, 'user.patientId'));

Expand Down
5 changes: 3 additions & 2 deletions app/accounts/AuthContext.working.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ async function fetchUser(setAuthContextState){
};

async function loginWithService(service, credentials){
console.log('AuthContext.loginWithService()', service, credentials);
// console.log('AuthContext.loginWithService()', service, credentials);

await accountsClient.loginWithService(service, credentials);
await fetchUser();
};

async function logout(){
console.log('AuthContext.logout()')
console.info('AuthContext.logout()')

await accountsClient.logout();
// setState({ loading: false, user: undefined });

Expand Down
12 changes: 7 additions & 5 deletions app/accounts/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { accountsClient } from './Accounts';
import { get } from 'lodash';
import jwt from 'jsonwebtoken';

import { log, message } from '../Logger';

const useStyles = makeStyles(theme => ({
cardContent: {
padding: theme.spacing(3),
Expand Down Expand Up @@ -68,7 +70,7 @@ const Login = function({ history }){
password: '',
code: ''
},
validate: function(values){
validate: function(values){
const errors = {};

if (!values.email) {
Expand All @@ -81,7 +83,7 @@ const Login = function({ history }){
},
onSubmit: async function(values, { setSubmitting }){

console.log('AccountsClient: Submiting username and password for authentication.')
console.log('AccountsClient: Submiting username and password for authentication.');

try {
await loginWithService('password', {
Expand All @@ -92,7 +94,7 @@ const Login = function({ history }){
// code: values.code
}, setError, async function setSuccess(result){
if(result){
console.log('loginWithService.result', result)
// console.log('loginWithService.result', result)

Session.set('sessionId', get(result, 'sessionId'));
// Session.set('sessionAccessToken', get(result, 'tokens.accessToken'));
Expand All @@ -101,10 +103,10 @@ const Login = function({ history }){
Session.set('lastUpdated', new Date());

let tokens = await accountsClient.getTokens();
console.log('tokens', tokens)
// console.log('tokens', tokens)
if(get(tokens, 'accessToken')){
let decoded = jwt.decode(tokens.accessToken, {complete: true});
console.log('decoded', decoded)
// console.log('decoded', decoded)
Session.set('accountsAccessToken', get(tokens, 'accessToken'))
Session.set('accountsRefreshToken', get(tokens, 'refreshToken'))
}
Expand Down
9 changes: 6 additions & 3 deletions app/accounts/Logout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { Session } from 'meteor/session';
import { Meteor } from 'meteor/meteor';

import jwt from 'jsonwebtoken';
import { log, message } from '../Logger';


// import { AccountsClient } from '@accounts/client';
// import { RestClient } from '@accounts/rest-client';
Expand Down Expand Up @@ -89,7 +91,7 @@ const Logout = function({ history }){

let currentUser = useTracker(function(){
return Session.get('currentUser');
}, [])
}, []);

//-----------------------------------------------------------
// Helper Functions
Expand All @@ -101,15 +103,16 @@ const Logout = function({ history }){
}

async function logoutUser(){
console.log('Logging out user session: ' + Session.get('accountsAccessToken'))
console.info('AccountsClient: Logging out user.')
console.debug('AccountsClient: User session: ' + Session.get('accountsAccessToken'))


await accountsClient.logout();
await accountsClient.clearTokens();

Meteor.call('jsaccounts/validateLogout', Session.get('accountsAccessToken'));

console.log('accountsClient.getTokens()', await accountsClient.getTokens());
console.debug('AccountsClient: getTokens()', await accountsClient.getTokens());

// close dialog
Session.set('mainAppDialogOpen', false);
Expand Down
Loading

0 comments on commit 4b716b1

Please sign in to comment.