You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. # Background
  2. log4jesus is an attempt to write a 'logging library' that has all of the practical benefits of a much larger logging library, but with no dependencies, and in much fewer lines of code, without sacrificing features, by taking a straight-forward approach of solving the problem at hand, and no other problems. There is nothing in this 'library' that could be called a 'system' or 'framework'. Just a few functions that actually do the work required.
  3. # Usage
  4. ```js
  5. const { log, logt } = require("./log4jesus");
  6. ```
  7. ## log
  8. send log data to targets tagged with 'all'
  9. ```js
  10. log("use", ["exactly", "like"], `console.log ${420 * 69}`)
  11. ```
  12. ## logt
  13. send log data to only targets tagged with one of the tags in the array passed as a first arguement.
  14. first argument can be a string or array of strings.
  15. ```js
  16. // send only to targets with the 'verbose' tag
  17. logt("verbose", "Download progress:", downloadProgress / totalDownloads);
  18. // send to targets with the 'info' and 'error' tags
  19. logt(["error", "info"], "failed to parse json at: ", filePath)
  20. ```
  21. # Configuration
  22. log4jesus supports 3 types of targets for your log data:
  23. - file
  24. - console
  25. - http
  26. to determine what logs go to which target, edit the file `log4jesus.json`.
  27. there are three arrays defined in that file, associated with a key of either 'file', 'console' or 'http.
  28. in each case, the array should be an array of objects with a `tags` property (which should be a string or array of strings), as well as some other details about how this target should operate.
  29. ## 'file' details
  30. - path: optional string to the file to create
  31. ## 'console' details
  32. - stdstream: required value of 'stdout', 'stderr', or 'stdin'. It's not usually desired to make it 'stdin'.
  33. ## 'http' details
  34. our http object is an extension of the [nodejs http/https options object](https://nodejs.org/api/http.html#httprequesturl-options-callback). The object is passed faithfully to http/s.request, so anything you add that is valid for http/s.request will be valid here.
  35. Add a 'url' field to the object to specify the url for the request, which should include both the port and protocol - you usually won't need to set 'hostname' or 'host', or 'path' or 'port' or 'protocol'.
  36. You may commonly have to set the 'headers' object, and the 'content-type' header inside of that object, depending on your server. If it's not provided it's set to 'text/plain'.
  37. ## timestamps
  38. all logs are prefixed with an ISO 8601 timestamp. You can change this easily by editing the `timestamp` function, but for now it is not configurable from the config file.
  39. ## output formatting
  40. by default, we format output using `util.format`, the same way console output is normally formatted. You can change this if you want by editing the `formatOutput` function, but for now it is not configurable from the config file.