@swissgeo/log 1.0.0-beta.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +110 -0
  2. package/package.json +7 -13
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # @swissgeo/log
2
+
3
+ Logging utilities for SWISSGEO projects.
4
+
5
+ ## Overview
6
+
7
+ This package provides a standardized logging utility for SWISSGEO projects, supporting various log levels, stylized console output with predefined colors, and structured message objects.
8
+
9
+ ### Why a dedicated package?
10
+
11
+ So that ESLint can be set to raise errors on console logs in the codebase, whilst having the possibility to write long-term logging in the code.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @swissgeo/log
17
+ ```
18
+
19
+ ## Features
20
+
21
+ - **Log Levels**: Support for `Error`, `Warn`, `Info`, and `Debug`.
22
+ - **Stylized Output**: Predefined background colors for log titles (using Tailwind-like colors).
23
+ - **Configurable Verbosity**: Easily control which log levels are output to the console.
24
+ - **Structured Messages**: Classes for defining messages with optional parameters (useful for i18n integration).
25
+
26
+ ## Usage
27
+
28
+ ### Basic Usage
29
+
30
+ The default export is a `log` object that provides methods for different log levels.
31
+
32
+ ```typescript
33
+ import log from '@swissgeo/log'
34
+
35
+ log.error('This is an error message')
36
+ log.warn('This is a warning')
37
+
38
+ // By default, info and debug levels are disabled
39
+ log.info('This will not be shown by default')
40
+ ```
41
+
42
+ ### Enabling Log Levels
43
+
44
+ You can control which levels are displayed by modifying the `wantedLevels` array.
45
+
46
+ ```typescript
47
+ import log, { LogLevel } from '@swissgeo/log'
48
+
49
+ // Enable all log levels
50
+ log.wantedLevels = [
51
+ LogLevel.Error,
52
+ LogLevel.Warn,
53
+ LogLevel.Info,
54
+ LogLevel.Debug
55
+ ]
56
+
57
+ log.info('Now this info message will be displayed')
58
+ ```
59
+
60
+ ### Styled Logs with Titles
61
+
62
+ You can provide an object to any log method to create a stylized title for your log message.
63
+
64
+ ```typescript
65
+ import log, { LogPreDefinedColor } from '@swissgeo/log'
66
+
67
+ log.info({
68
+ title: 'API',
69
+ titleColor: LogPreDefinedColor.Sky,
70
+ messages: ['Fetching data from server...', { url: '/api/data' }]
71
+ })
72
+
73
+ log.warn({
74
+ title: 'DEPRECATED',
75
+ titleColor: LogPreDefinedColor.Amber,
76
+ messages: ['This method will be removed in v2.0']
77
+ })
78
+ ```
79
+
80
+ ### Using Message Classes
81
+
82
+ The package also provides `Message`, `ErrorMessage`, and `WarningMessage` classes for structured data, to help their integration in translation tools such as `vue-i18n`.
83
+
84
+ ```typescript
85
+ import { Message, ErrorMessage } from '@swissgeo/log'
86
+
87
+ const msg = new Message('translation.key', { count: 5 })
88
+ const errorMsg = new ErrorMessage('error.occurred')
89
+
90
+ console.log(msg.msg) // 'translation.key'
91
+ console.log(msg.params) // { count: 5 }
92
+
93
+ // and can then be used as (in vue-i18n context)
94
+ t(msg.msg, msg.params)
95
+ // translation exemple (using params to swap placeholders) => "There was an error with 5 problems"
96
+
97
+ ```
98
+
99
+ ## Available Colors
100
+
101
+ `LogPreDefinedColor` includes a wide range of colors based on TailwindCSS (using OKLCH):
102
+ `Red`, `Orange`, `Amber`, `Yellow`, `Lime`, `Green`, `Emerald`, `Teal`, `Cyan`, `Sky`, `Blue`, `Indigo`, `Violet`, `Purple`, `Fuchsia`, `Pink`, `Rose`, `Slate`, `Gray`, `Zinc`, `Neutral`, `Stone`.
103
+
104
+ ## License
105
+
106
+ BSD-3-Clause
107
+
108
+ ## Repository
109
+
110
+ [https://github.com/geoadmin/web-mapviewer](https://github.com/geoadmin/web-mapviewer)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swissgeo/log",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0",
4
4
  "description": "Logging utils for SWISSGEO projects.",
5
5
  "license": "BSD-3-Clause",
6
6
  "type": "module",
@@ -20,22 +20,16 @@
20
20
  "dist"
21
21
  ],
22
22
  "devDependencies": {
23
- "@microsoft/api-extractor": "^7.55.0",
24
- "@prettier/plugin-xml": "^3.4.2",
25
- "eslint": "^9.39.1",
26
- "prettier": "^3.6.2",
27
- "prettier-plugin-jsdoc": "^1.5.0",
28
- "prettier-plugin-packagejson": "^2.5.19",
29
- "prettier-plugin-tailwindcss": "^0.7.1",
23
+ "@microsoft/api-extractor": "^7.55.2",
24
+ "eslint": "^9.39.2",
30
25
  "typescript": "^5.9.3",
31
26
  "unplugin-dts": "1.0.0-beta.6",
32
- "vite": "^7.2.2",
33
- "@swissgeo/config-eslint": "1.0.0-beta.2",
34
- "@swissgeo/config-typescript": "1.0.0-beta.2",
35
- "@swissgeo/config-prettier": "1.0.0-beta.2"
27
+ "vite": "7.2.2",
28
+ "@swissgeo/config-eslint": "1.0.0",
29
+ "@swissgeo/config-typescript": "1.0.0"
36
30
  },
37
31
  "peerDependencies": {
38
- "proj4": "^2.20.0"
32
+ "proj4": "^2.20.2"
39
33
  },
40
34
  "scripts": {
41
35
  "build": "pnpm run type-check && pnpm run generate-types && vite build",