GithubHelp home page GithubHelp logo

destinmoulton / chronicle-console Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 217 KB

A simple logging library that uses the Chronicle API to store app logs.

License: MIT License

JavaScript 62.62% HTML 3.54% TypeScript 33.84%

chronicle-console's Introduction

Chronicle Console

Usage

Log user actions:

console.action("login");
console.action("click", "information button");

Standard console logging is also sent to the server:

console.assert(<predicate>, "Message on failure");
console.log("message");
console.error("Error!");

Collected Data

Along with the data (strings, numbers, arrays, or objects), a stack trace is taken and logged when each enabled method is called. As such, you don't need to create an additional console.trace() call and can likely leave trace out of the methodsToLog array.

Configuration

Option Required Description Default
server * The URL of the Chronicle Logger.
app * The name of this app.
env Environment information. window.navigator
toConsole Show messages in regular console. true
globalize Overwrite the global console object. false
consoleObject A console object.
Useful for testing/mocking.
console
methodsToLog Array of methods that are logged.
Does not effect toConsole option.
["action","error","warn","assert"]
customMethods Array of strings for custom logging methods.
Do not include in methodsToLog.
[]

methodsToLog

The methodsToLog configuration option is used to determine which standard console methods are logged. Many apps will probably not want to store console.log() messages, however console.error and the custom console.action are useful for tracking bugs and user actions.

Stack Traces

Every log method includes a stack trace, this means that you don't need to call the console.trace() command to get a trace.

Custom Methods

You can easily add your own custom logging method names.

const config = {
    server: "https://xyz.chronicle.logging.server.com",
    app: "My App",
    globalize: true,
    methodsToLog: ["error", "warn"],
    customMethods: ["crash"]
};

ChronicleConsole.init(config);

ChronicleConsole.crash("The system has crashed!");
console.crash("Frontend has crashed");
// Logs crash to server but does NOT log to console
// Includes a stack trace

React Native Device Info

The npm package react-native-device-info can be linked into a react application, giving access to a variety of device info.

Chronicle can be configured to overwrite the env variable, allowing storage of certain native device information.

import DeviceInfo from "react-native-device-info";

const reactEnv = {
    appName: DeviceInfo.getApplicationName(),
    userAgent: DeviceInfo.getUserAgent(),
    brand: DeviceInfo.getBrand(),
    buildNumber: DeviceInfo.getBuildNumber(),
    bundleId: DeviceInfo.getBundleId(),
    deviceCountry: DeviceInfo.getDeviceCountry(),
    deviceId: DeviceInfo.getDeviceId(),
    deviceLocale: DeviceInfo.getDeviceLocale(),
    deviceName: DeviceInfo.getDeviceName(),
    manufacturer: DeviceInfo.getManufacturer(),
    model: DeviceInfo.getModel(),
    systemName: DeviceInfo.getSystemName(),
    systemVersion: DeviceInfo.getSystemVersion(),
    timezone: DeviceInfo.getVersion(),
    uniqueId: DeviceInfo.getUniqueID(),
    version: DeviceInfo.getVersion(),
    isEmulator: DeviceInfo.isEmulator(),
    isTablet: DeviceInfo.isTablet()
};

const config = {
    app: "Test App",
    server: "https://console.api.url",
    globalize: false,
    env: reactEnv,
    methodsToLog: ["action", "error", "warn"],
    toConsole: true
};

chronicle.init(config);

License

MIT

chronicle-console's People

Contributors

destinmoulton avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.