logging.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Utilities: A classic collection of JavaScript utilities
  3. * Copyright 2112 Matthew Eernisse ([email protected])
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. var assert = require('assert')
  19. , logger = require('../lib/log')
  20. , tests;
  21. tests = {
  22. 'test basic logging': function () {
  23. var oldLog = console.log;
  24. console.log = function (str) {
  25. assert.equal(str, "basic log");
  26. };
  27. logger.log("basic log");
  28. console.log = oldLog;
  29. }
  30. , 'test info logging': function () {
  31. var oldinfoLog = console.info;
  32. console.info = function (str) {
  33. assert.equal(str, "info log");
  34. };
  35. logger.info("info log");
  36. console.info = oldinfoLog;
  37. }
  38. , 'test warning logging': function () {
  39. var oldwarnLog = console.warn;
  40. console.warn = function (str) {
  41. assert.equal(str, "warn log");
  42. };
  43. logger.warn("warn log");
  44. console.warn = oldwarnLog;
  45. }
  46. , 'test error logging': function () {
  47. var oldErrorLog = console.error;
  48. console.error = function (str) {
  49. assert.equal(str, "error log");
  50. };
  51. logger.error("error log");
  52. console.error = oldErrorLog;
  53. }
  54. }
  55. module.exports = tests;