Skip to content

Commit

Permalink
Open sourcing electrode-ui-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
dvonlehman committed Jul 28, 2017
1 parent 102be75 commit eacee71
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 33 deletions.
3 changes: 3 additions & 0 deletions packages/electrode-ui-logger/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
extends:
- "./node_modules/electrode-archetype-njs-module-dev/config/eslint/.eslintrc-node"
228 changes: 228 additions & 0 deletions packages/electrode-ui-logger/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@

# Created by https://www.gitignore.io/api/osx,node

### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

### Vim template
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~
### GitBook template
# Node rules:
## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

## Dependency directory
## Commenting this out is preferred by some people, see
## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git
node_modules

# Book build output
_book

# eBook build output
*.epub
*.mobi
*.pdf
### TortoiseGit template
# Project-level settings
/.tgitconfig
### Xcode template
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
### Emacs template
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/
### OSX template
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
/xclap.js
/.npmignore
.nyc_output
/test
/.eslintrc
16 changes: 3 additions & 13 deletions packages/electrode-ui-logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

Log well and prosper. Happy Logging!

Lead Maintainer: [Andy Pham](https://gecgithub01.walmart.com/apham)

This is a logger for UI code with an Electrode server as backend support.

It requires the [electrode-logging] module and the API from [electrode-log-consumer] to work.

If you are using [electrode-server], then the [electrode-logging] and the [electrode-log-consumer] API should've been setup in your backend automatically.

When your UI code is running on the browser, the logger will save up your logs and send them to the log API `{basePath}/api/logger` every **10** seconds.

When your UI code is running on the server for SSR, the logger will call `request.log`. This is why the `request` option is required on the server.

# Install

```bash
$ npm install @walmart/electrode-ui-logger --save
$ npm install electrode-ui-logger --save
```

# Logger usage

The logging interface provides a simple api for generating developer logs.

```js
import logger from "@walmart/electrode-ui-logger";
import logger from "electrode-ui-logger";

logger.log(tags, data, options);

Expand Down Expand Up @@ -78,8 +72,4 @@ These are the API aliases for different log levels:
* `logger.error(data, options)`
* `logger.debug(data, options)`
* `logger.trace(data, options)`


[electrode-server]: https://gecgithub01.walmart.com/electrode/electrode-server
[electrode-logging]: https://gecgithub01.walmart.com/electrode/electrode-logging
[electrode-log-consumer]: https://gecgithub01.walmart.com/electrode/electrode-log-consumer

14 changes: 10 additions & 4 deletions packages/electrode-ui-logger/lib/csindex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
/* eslint-disable */

var stringify = require('json-stringify-safe');
var Config = require("@walmart/electrode-ui-config");
var fetch = require("@walmart/electrode-fetch").fetch;
var safeEventBuilder = require("./safe-event-builder");
var Log = require("./logger");

// Require the fetch polyfill
require("whatwg-fetch");

Log._stream = [];
Log.fetch = fetch;
Log.fetch = window.fetch;
Log.config = require("electrode-ui-config");

Log.setFetch = function (_fetch) {
Log.fetch = _fetch;
};

Log.setConfig = function (_config) {
Log.config = _config;
};

Log._flush = function () {
if (Log._stream.length > 0) {
var payload = {
Expand All @@ -33,7 +39,7 @@ Log._flush = function () {

Log._stream = [];

return Log.fetch(Config.fullApiPath("/logger"), payload);
return Log.fetch(Log.config.fullApiPath("/logger"), payload);
}
};

Expand Down
41 changes: 26 additions & 15 deletions packages/electrode-ui-logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electrode-ui-logger",
"version": "4.0.0",
"version": "1.0.0",
"description": "Electrode Logging Utility for UI code",
"main": "./lib/index.js",
"browser": "./lib/csindex.js",
Expand All @@ -9,27 +9,38 @@
"test": "test"
},
"scripts": {
"test": "xclap check",
"coverage": "builder run check",
"prepublish": "builder run check"
"test": "clap check",
"format": "prettier --write --print-width 100 *.js `find . -type d -d 1 -exec echo '{}/**/*.js' \\; | egrep -v '(/node_modules/|/dist/|/coverage/)'`"
},
"repository": {
"type": "git",
"url": "[email protected]:electrode/electrode-ui-logger.git"
"url": "https://github.com/electrode-io/electrode.git"
},
"keywords": [],
"license": "Apache-2.0",
"devDependencies": {
"electrode-archetype-njs-module-dev": "^2.2.0"
},
"license": "UNLICENSED",
"dependencies": {
"@walmart/electrode-fetch": "^6.0.0",
"@walmart/electrode-logging": "^3.1.5",
"electrode-ui-config": "^1.0.0",
"json-stringify-safe": "^5.0.1",
"lodash.keys": "^4.2.0",
"lodash.omit": "^4.5.0"
"lodash.omit": "^4.5.0",
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
"@walmart/electrode-archetype-hapi-plugin-dev": "^2.0.0",
"babel-loader": "^7.1.0",
"bluebird": "^2.10.2",
"builder": "^3.1.0",
"webpack": "^3.0.0"
"nyc": {
"all": true,
"reporter": [
"lcov",
"text",
"text-summary"
],
"exclude": [
"coverage",
"*clap.js",
"gulpfile.js",
"dist",
"test"
]
}
}
2 changes: 1 addition & 1 deletion packages/electrode-ui-logger/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
extends:
- "../node_modules/@walmart/electrode-archetype-hapi-plugin-dev/config/eslint/.eslintrc-test"
- "../node_modules/electrode-archetype-njs-module-dev/config/eslint/.eslintrc-test"
2 changes: 2 additions & 0 deletions packages/electrode-ui-logger/test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--require node_modules/electrode-archetype-njs-module-dev/config/test/setup.js
--recursive
Loading

0 comments on commit eacee71

Please sign in to comment.