Skip to content

Commit

Permalink
Merge pull request #2 from OnrampLab/feat-1-init
Browse files Browse the repository at this point in the history
Feat 1 init
  • Loading branch information
glennfriend authored Jan 9, 2020
2 parents bbe287f + 7af1d1b commit f17cfc7
Show file tree
Hide file tree
Showing 18 changed files with 1,458 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# 2 space indentation
[**.*]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand Down
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# universal-loggly

## feature
- send log to Loggly

## how to build
- yarn dev
- yarn prod

## laravel dependency
- .env
- .env.example

## API dependency
- Loggly fetch url API

## node dependency
- yarn add cross-fetch

## webpack dependency
- yarn add dotenv-webpack

## include example
- vi /your-project/app.js
```js
// from origin
import { LogglyClient } from 'universal-loggly';

// from custom helper
import { factoryLogglyClient } from 'universal-loggly-helper';
```

## sample code
```js
import { factoryLogglyClient } from 'universal-loggly-helper';

const message = 'test message';
const redirectUrl = 'https://duckduckgo.com/';
const promise = logger.info(message);

promise.then(function(data) {
// success
})
.catch(function(error) {
// skip
})
.finally(function() {
window.location.href = redirectUrl;
});
```

## for develop library
```
cd /var/www/library-app
yarn link
> success Registered "library-app"
cd /var/www/your-main-project
yarn link "library-app"
> success Using linked package for "library-app"
yarn unlink "library-app"
> success Removed linked package "library-app"
```

## plan of future
- ES8 async/await
- storage cookie
- send hook
1 change: 1 addition & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Demo</h1>
43 changes: 43 additions & 0 deletions example/universal-loggly-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import getConfig from "next/config";
import { LogglyClient } from "universal-loggly";

const tags = "localhost, staging, test-only";

function getToken() {
return process.env.LOGGLYPLUS_TOKEN;
}

function getToken_2() {
const { publicRuntimeConfig } = getConfig() || {};
const { LOGGLYPLUS_TOKEN } = publicRuntimeConfig || {};
return LOGGLYPLUS_TOKEN;
}

// factoryLogger()
export function factoryLogglyClient() {
const token = getToken();

const logger = new LogglyClient(token, tags);
return logger;
}

/*
const logger = factoryLogglyClient();
const message = 'test message';
const promise = logger.info(message, {
redirect_result: true,
redirect_url: 'https://127.0.0.1',
});
promise
.then(function(data) {
console.log('log ok');
})
.catch(function(error) {
console.error(`[universal-loggly]: ${error}`);
})
.finally(function() {
console.log('log final');
});
*/
Loading

0 comments on commit f17cfc7

Please sign in to comment.