-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.html
50 lines (47 loc) · 1.55 KB
/
index.test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Logga browser test</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="./dist/browser/index.js"></script>
</head>
<body>
<style>
div {
position: relative;
max-width: 20rem;
margin: 1rem auto;
padding: 1rem;
border: 1px solid #ddd;
border-radius: 3px;
}
div::after {
content: '❌';
position: absolute;
top: 2px;
right: 5px;
}
</style>
<script>
const log = logga.getLogger('test:browser')
// Defaults to output to the developer console
log.info('This info should be in the console')
log.warn('This warning should be in the console')
log.error('This error should be in the console')
// Also send to an alert dialog
logga.addHandler(({message}) => alert(message))
log.warn('This warning should be in an alert (and in the console)')
// Instead, handle log events with simple "toasts"
logga.replaceHandlers(({level, message}) => {
const elem = document.createElement('div')
elem.innerHTML = message
elem.onclick = event => document.body.removeChild(event.target)
document.body.appendChild(elem)
})
log.info('This info should be in the document (and not in the console, or in an alert)')
setTimeout(() => log.warn('Same for this warning'), 2000)
</script>
</body>
</html>