Skip to content
This repository has been archived by the owner on Apr 27, 2019. It is now read-only.

4 · API : Scribe

Guillaume Wuip edited this page Feb 2, 2015 · 1 revision
var scribe = require('scribe')();

##scribe(config)

Params :

  • config : Optional.
    • rootPath : logs folder for LogWriter. Default /logs
    • createDefaultConsole : Boolean. If true : create a Console2 instance attached to process.console. Default true. See Using Scribe through your modules

Return : an object with this properties

  • console
  • webPanel
  • express
  • LogWriter
  • Console2

###scribe.console(config, logWriter)

Create a new Console2 instance with LogWriter listening. This is the best way to create a console.

Params :

  • config
    • console : Optional. Console2 options
    • logWriter : Optional. Boolean|Object. If false, don't save logs on disk.
      • rootPath : directory where to store logs
    • createBasic : Optional. Boolean. true to create basic loggers. Default true.
  • logWriter : Optional. A custom LogWriter instance to use.

Return : A Console2 instance.

Example :

var console = scribe.console();

var anotherConsole = scribe.console({
    console : myConsole2Config,
    createBasic : false
});

####Basic loggers When passing true as the createBasic config, you ask ScribeJS to create default loggers to the new console you're builting.

These loggers are :

  • log()
  • info()
  • error()
  • warning()
  • dir()

See /examples/basic.js

###scribe.webPanel()

Return : an express router

Example : (assuming you have an app express server)

app.use('/logs', scribe.webPanel());

###scribe.express.logger(console, validate)

Params:

  • console : Optional. An instance of Console2 with an .info() logger. If no console provided, Scribe will try to use process.console if it exists. If not, it will throw an error.
  • validate : a filter function that receive req and res as arguments and should return true in order to Scribe to log that request.

Return : a function that log every request

Example :

app.use(scribe.express.logger());

See also : /examples/expressLogger_custom.js

###scribe.LogWriter

LogWriter constructor

Use the constructor to built your own instance of LogWriter. Usefull when you need, by example, to change to full path of a log file. Default is : [YYYY]/[MM]/[DD_MM_YY].[logger].json.

You can by example change it to [user]/[logger]/[DD_MMM_YY].[logger].json. See /examples/logWriter_config.js.

###scribe.Console2

Console2 constructor

Don't use it directly but use scribe.console() instead in order to hook LogWriter logic (and others) on the new console.

Clone this wiki locally