npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ionic-log-file-appender

v2.0.7

Published

A simple rolling log file appender for Ionic Cordova

Downloads

40

Readme

ionicLogFileAppender

Simple log file appender for Ionic 3.

  • Creates rolling log files date-stamped up to a specified max size.
  • Optionally logs to console.
  • Only writes log files if running on a Cordova platform (not in the browser)

Installation

npm install --save ionic-log-file-appender

Dependencies

Ionic Native File:

https://ionicframework.com/docs/native/file/

Configuration

Logging configuration is specified by passing a ILogProviderConfig object into the init function of the LogProvider.

{
  // If true, logs verbose details of file logging operations to console
  enableMetaLogging: boolean;

  // If true, all file log messages also appear in the console
  logToConsole: boolean;

  // Date format used in log statements
  logDateFormat: string;

  // Date format used in log file names.
  // NOTE: be careful with special characters like ':' as this can cause file system issues
  fileDateFormat: string;

  // Maximum number of log statements before file rollover
  fileMaxLines: number;

  // If the last log file exceeds this size on initialization, a new log file will be created
  fileMaxSize: number;

  // If the total size of all log files exceeds this size on initialisation, oldest files will be removed
  totalLogSize: number;

  // Name of directory to create for logs, within application's data directory
  logDir: string;

  // Prefix for log files
  logPrefix: string;

  // Developer-level logging will appear in log files if true
  devMode: boolean;
  
  // Name of directory in which to create log directory
  baseDir: string;
}

Any values not specified in the passed-in value will be set to the defaults below:

{
  enableMetaLogging: false,
  logToConsole: false,
  logDateFormat: 'yyyy-MM-dd HH:mm:ss.SSS',
  fileDateFormat: 'yyyy-MM-dd_HH-mm-ss-SSS',
  fileMaxLines: 2000,
  fileMaxSize: 1000000,
  totalLogSize: 5000000,
  logDir: 'logs',
  logPrefix: 'log',
  devMode: false,
  baseDir: <dataDirectory>
}

where dataDirectory is defined by the Ionic File plugin.

Reference in Application module

import {File} from '@ionic-native/file';
import {Platform} from 'ionic-angular';
import {DatePipe} from '@angular/common';
import {LogProvider, LogFileAppenderModule} from 'ionic-log-file-appender';

...


@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    ...
    LogFileAppenderModule.forRoot(),
    ...
  ]
  
  
  ...
  
  providers: [
      ...
      File,
      DatePipe,
      LogProvider,
      ...
  ]
})
export class AppModule { }

Initialisation in application component

  platform.ready().then(() => {
    return log.init({
      /* Your config here */
    });
  });

Usage in a class via dependency injection

export class SomeClass {
  constructor(private log: LogProvider) {
  }
  
  doSomething() {
    this.log.log('Something has been done!');
    this.log.logDev('Something has been done, but will only be logged in if devMode is true');
    const errorObj = {message: 'FooBar error', code: 128};
    this.log.err('Something unexpected happened and the error object will be printed', errorObj);
    this.log.err('Something unexpected happened and the error object will not be printed');
  }
  
  getTheLogs() {
    this.log.getLogFiles()
          .then((files: Entry[]) => {
            // Do something with the files!
          })
          .catch(err => {
            // Oops, there was an error!
          });
  }
}