* A shallow copy of an object. Bunyan logging attempts to never cause * exceptions, so this function attempts to handle non-objects gracefully.
(obj)
| 114 | * exceptions, so this function attempts to handle non-objects gracefully. |
| 115 | */ |
| 116 | function objCopy(obj) { |
| 117 | if (obj == null) { // null or undefined |
| 118 | return obj; |
| 119 | } else if (Array.isArray(obj)) { |
| 120 | return obj.slice(); |
| 121 | } else if (typeof (obj) === 'object') { |
| 122 | var copy = {}; |
| 123 | Object.keys(obj).forEach(function (k) { |
| 124 | copy[k] = obj[k]; |
| 125 | }); |
| 126 | return copy; |
| 127 | } else { |
| 128 | return obj; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | var format = util.format; |
| 133 | if (!format) { |